0

UINavigationItemのtouchViewにビューを設定し、それにタップジェスチャレコグナイザーを追加しています。奇妙なことに、タップがビューの外にある場合でも、タップ認識機能が呼び出されます。なぜこれが起こっているのか考えていますか?

UIView *testView = [[UIView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 120.0f, 20.0f)];
testView.backgroundColor = [UIColor redColor];
UIGestureRecognizer *tapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(doStuff:)];
tapRecognizer.cancelsTouchesInView = YES;
[testView addGestureRecognizer:tapRecognizer];
testView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
self.navigationItem.titleView = testView;

赤いボックスの外側をクリックしても、ジェスチャ認識機能をトリガーできます。

4

1 に答える 1

-1

このように使う

UITapGestureRecognizer *tapRecognizer = 
  [[UITapGestureRecognizer alloc] initWithTarget:self 
                                          action:@selector(doStuff:)];

このコードの代わりに

 UIGestureRecognizer *tapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(doStuff:)];
于 2013-01-29T18:22:49.180 に答える