我正在我的 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;
我可以在红框外点击,仍然触发手势识别器。