- (voID)vIEwDIDLoad { [super vIEwDIDLoad]; UITapGestureRecognizer *_tapOnVIDeoRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(toggleControlsVisible)]; [self.vIEw addGestureRecognizer:_tapOnVIDeoRecognizer]; UIVIEw *smallVIEw=[[UIVIEw alloc] initWithFrame:CGRectMake(0,200,200)]; smallVIEw.backgroundcolor=[UIcolor redcolor]; smallVIEw.exclusivetouch=YES; smallVIEw.userInteractionEnabled=YES; [self.vIEw addSubvIEw:smallVIEw]; } - (voID)toggleControlsVisible { NSLog(@"tapped"); }
当我点击小视图时,它仍会在self.vIEw中触发点击事件. Xcode记录“轻拍”.如何拦截从smallVIEw到self.vIEw的手势事件?
解决方法 像这样实现UIGestureRecognizer委托方法shouldReceivetouch.如果触摸位置在topVIEw内,请勿接触.- (BOol)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceivetouch:(UItouch *)touch{ CGPoint location = [touch locationInVIEw:self.vIEw]; if (CGRectContainsPoint(self.topVIEw.frame,location)) { return NO; } return YES;}总结
以上是内存溢出为你收集整理的iOS:截取从顶视图到底视图的轻击手势事件全部内容,希望文章能够帮你解决iOS:截取从顶视图到底视图的轻击手势事件所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)