我创建了主UIView
。然后在其上添加两个UIView。
并将UIGestureRecognizer
附加到mainView。但是当我点击主视图时,它只能检测到mainView的一半。
有谁知道这是为什么,
-(void)addTapGesture:(UIView*)view
{
view.userInteractionEnabled=YES;
UITapGestureRecognizer *oneFingerTwoTaps =
[[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(detailInfo:)] autorelease];
// Set required taps and number of touches
[oneFingerTwoTaps setNumberOfTapsRequired:1];
[oneFingerTwoTaps setNumberOfTouchesRequired:1];
oneFingerTwoTaps.delegate=self; //gesturRecognize delegate
// Add the gesture to the view
[view addGestureRecognizer:oneFingerTwoTaps];
}
答案 0 :(得分:0)
检查是否有其他视图重叠你的mainView图层,或者你的mainView上是否添加了其他一些可能取消你的主视图的访客
答案 1 :(得分:0)
使您的ViewController符合<UIGestureRecoganizerDelegate>
然后在viewController中调用delegate方法。
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
{
NSLog ("Touch View : %@", touch.view);
NSLog ("GestureRecoganizer View : %@", touch.view); //Check if both views are same
if ([touch.view isKindOfClass: [YourViewClass class]]) {
return NO;
}
return YES;
}
希望它能帮助你...快乐编码:)