0

iPad のテーブル ビュー セルに配置されたボタンに奇妙な問題があります。

理解を深めるための 2 つのスクリーンショットを次に示します (ボタンは右側にあり、背景色は白です)。

iPhone

iPad

iPhone では問題ありませんが、iPad ではこのボタンが反応しません。正しく描かれているので、配置は合っているようです。

これは私のカスタム UITableViewCell のコードです:

rightButton = [UIButton buttonWithType:UIButtonTypeCustom];
[rightButton setContentMode:UIViewContentModeCenter];
[rightButton setBackgroundColor:[UIColor whiteColor]];
int xPos = buttonWidth-rightButton.frame.size.width;
[rightButton setFrame:CGRectMake(xPos, 0, buttonHeight, buttonHeight)];
[self.contentView addSubview:rightButton];

//buttonWidth = 310, buttonHeight = 60

イメージとターゲットは別のクラスによって設定されます。

[cell.rightButton setImage:[UIImage imageNamed:@"options.png"] forState:UIControlStateNormal];
[cell.rightButton addTarget:self action:@selector(showOptions:) forControlEvents:UIControlEventTouchUpInside];

すべての要素をセルに配置した後、これも試しました

 [self.contentView bringSubviewToFront: rightButton];

ボタンが一番上になるようにします。

うまくいきませんでした。

これに関するアイデアはありますか?


私はまだ解決策を見つけることができませんでした。

その間に私がしたこと:

  • セルに配置されたすべてのオブジェクトを視覚化しました(不要な重なりを表示するため)
  • 他のすべてのセル オブジェクトでのユーザー操作を無効にしました

他のアイデアはありますか?

4

2 に答える 2

0

さて、私は何かを見つけました:

iPad の場合、ボタンは水平方向の最初の 320 ピクセルの間に配置された場合にのみ反応します。

ボタンに触れたときにデバッガーが言うことは次のとおりです (右側に配置されています)。

(lldb) po touches
(NSSet *) $1 = 0x08249cd0 {(
<UITouch: 0x82c63d0> phase: Began tap count: 1 window: <UIWindow: 0x8266ca0;
frame = (0 0; 768 1024); opaque = NO; autoresize = RM+BM; 
layer = <UIWindowLayer: 0x8266d60>> view: <SBMultiCell: 0x82cb8a0; baseClass = UITableViewCell; 
frame = (0 0; 744 93); autoresize = W; layer = <CALayer: 0x82cb830>> 
location in window: {713, 123} previous location in window: {713, 123} 
location in view: {701, 44} previous location in view: {701, 44}
)}

(lldb) po rightButton
(UIButton *) $2 = 0x082cd500 <UIButton: 0x82cd500; 
frame = (658 0; 86 86); opaque = NO; layer = <CALayer: 0x82cd5e0>>

タッチ位置はボタンの寸法の間に正確にあり、すべてが正しく描画されます。そして前にも書きましたが、重複要素などはありません…

于 2012-08-02T16:56:54.960 に答える
0

最初にこれを試してください:

rightButton = [UIButton buttonWithType:UIButtonTypeCustom];
[rightButton setContentMode:UIViewContentModeCenter];
[rightButton setBackgroundColor:[UIColor whiteColor]];
int xPos = buttonWidth-rightButton.frame.size.width;
[rightButton setFrame:CGRectMake(xPos, 0, buttonHeight, buttonHeight)];
[self.contentView addSubview:rightButton];
[self.contentView bringSubviewToFront: rightButton]
[self.contentView bringSubviewToFront: rightButton];
rightButton.userInteractionEnabled = YES;

[cell.rightButton setImage:[UIImage imageNamed:@"options.png"] forState:UIControlStateNormal];
[cell.rightButton addTarget:self action:@selector(showOptions:) forControlEvents:UIControlEventTouchUpInside];
[cell.rightButton setUserInteractionEnabled:YES];

または、ボタンにタップ ジェスチャを追加することもできます。これで問題が解決します。この行の代わりに、

[cell.rightButton addTarget:self action:@selector(showOptions:) forControlEvents:UIControlEventTouchUpInside];

これを書いて、

UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(showOptions:)];
cell.rightButton addGestureRecognizer:tap];
[cell.rightButton setUserInteractionEnabled:YES];
于 2012-07-24T17:47:03.277 に答える