UIVIEw *supervIEw = [[UIVIEw alloc] initWithFrame:CGRectMake:(0,320,480);UIVIEw *subvIEw = [[UIVIEw alloc] initWithFrame:CGRectMake:(100,100,100);UIPanGestureRecognizer *recognizer = [[UIPanGestureRecognizer alloc] initWithTarget: self action: @selector(handleTap);supervIEw.userInteractionEnabled = YES;subvIEw.userInteractionEnabled = NO;[supervIEw addGestureRecognizer:recognizer];[self addSubvIEw:supervIEw];[supervIEw addSubvIEw:subvIEw];
识别器也会在子视图中触发,有没有办法从子视图中排除识别器?
我知道之前已经问过这个问题,但我没有找到一个好的答案.
解决方法 您可以使用手势识别器委托来限制可以识别触摸的区域,类似于此示例:recognizer.delegate = self;...- (BOol)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceivetouch:(UItouch *)touch{ CGPoint touchPoint = [touch locationInVIEw:supervIEw]; return !CGRectContainsPoint(subvIEw.frame,touchPoint);}
请注意,您需要保持对父视图和子视图的引用(使它们成为实例变量?)才能在委托方法中使用它们
总结以上是内存溢出为你收集整理的ios – 从UITapGestureRecognizer中排除子视图全部内容,希望文章能够帮你解决ios – 从UITapGestureRecognizer中排除子视图所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)