关于UIScrollView事件

- (BOOL)touchesShouldCancelInContentView:(UIView *)view

Parameters


view


The view object in the content that is being touched.

view 这个view对象已获取到touched事件

Return Value

YES to cancel further touch messages to view, NO to have view continue to receive those messages.

The default returned value is YES if view is not a UIControl object; otherwise, it returns NO.

返回YES 在这个view上取消进一步的touched消息(不在这个view上处理,事件传到下一个view)。如果这个参数view不是一个UIControl对象,默认返回YES。如果是一个UIControl 对象返回NO.

The scroll view calls this method just after it starts sending tracking messages to the content view. If it receives NO from this method, it stops dragging and forwards the touch events to the content subview. The scroll view does not call this method if the value of the canCancelContentTouches property is NO.

scroll view调用这个函数,在发送taking消息到内容视图之后。如果返回NO,scroll view会停止拖动,触摸事件向子view传递。如果 canCancelContentTouches属性设置为NO 这个函数就不会调用

只有scrollView的canCancelContentTouches字段为YES 且 (BOOL)touchesShouldBegin:withEvent:inContentView:返回YES时,这个方法touchesShouldCancelInContentView:才会被调用。

什么情况下touchesShouldBegin返回YES呢? 在点击到scrollView上子视图的时候返回YES,表示让子视图也接收事件

touchesShouldCancelInContentView:

返回YES,表示当前view对这个事件不感兴趣,会传递到其他view

返回NO,scroll view会停止拖动,触摸事件交由该view处理或向子view传递。

总结:

在scroll view上添加一个button当在这个button上滑动的时候,scroll view并不会滑动,因为根据touchesShouldCancelInContentView:的解释该button是一个UIControl对象默认是返回NO。那么怎么能够实现在button上可以滑动scrollview呢?在touchesShouldCancelInContentView的时候返回YES,就可以了。

时间: 2024-07-30 11:11:52

关于UIScrollView事件的相关文章

UIScrollView事件拦截

在日常的开发中,我们经常会用到UIScrollView,然而,它是一个问题频出的控件,比如在nib中使用它就必须手动为它创建一个ContentView.当然了使用春代码的时候使用了懒加载机制使得它能够拥有一个contentView,今天我们不谈这个问题,我们来谈谈UIScrollView的事件拦截相关的知识. 在进入正题之前,先补个知识点:响应链「Responder Chain」.iOS设备的屏幕上有很多的元素,当用户触发了一个事件之后: 用户触发事件 ->系统框架UIKit创建一个包含该事件各

uiscrollview 事件冲突

self.scrollView.panGestureRecognizer.delaysTouchesBegan = YES;设置scrollView的延迟接收点击触摸事件,关闭触摸事件 self.scrollView.delaysContentTouches = YES; button无法识别点击事件 既要能实现button点击效果,又要实现画板画画无延迟,那么解决办法来啦~首先要设置scrollView的两个属性 self.scrollView.canCancelContentTouches

【ios控件】UIScrollView 事件说明

1 // 2 // UIDemoViewController.m 3 // 06-1UIScrollDemo 4 // 5 // Created by k on 14-9-4. 6 // Copyright (c) 2014年 com.akleee.www. All rights reserved. 7 // 8 9 #import "UIDemoViewController.h" 10 11 @interface UIDemoViewController ()<UIScroll

iOS UIScrollView不能响应TouchBegin事件的处理方法:

原因:UIView的Touch事件被UIScrollview捕获了,所以UIView里面的Touch事件没有响应——————解决方法:将UIScrollview的捕获的Touch事件往上传:————给UIScrollview添加类别:UIScrollView+UITouch.h 代码: #import "UIScrollView+UITouch.h" @implementation UIScrollView (UITouch) -(void)touchesBegan:(NSSet<

UIScrollView不接受UITouch事件的解决方法

原因是:UIView的touch事件被UIScrollView捕获了. 解决办法:让UIScrollView将事件传递过去.于是最简单的解决办法就是加一个UIScrollView的category.这样每个用到UIScrollView的地方只要导入这个category就可以直接响应相关的touch事件了.我也是从别人的那参考过来的,纪录一下. 直接上代码 #import "UIScrollView+UITouch.h" @implementation UIScrollView (UIT

UIScrollView无法响应touch事件的解决方法

用过UIScrollView的都会发现UIScrollView不会响应touch事件,这样就无法在touches相关的方法中做一些事情了,比如收回键盘等等.其实写个categroy就可以解决这个问题了. 具体实现如下: @implementation UIScrollView (UITouchEvent) - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { [[self nextResponder] touches

UIScrollView中的UITableView接收不到点击事件

一个UIScrollView中有若干个UITextfield,为了能在空白处点击能隐藏键盘,加了UITapGestureRecognizer事件,结果导致同样在UIScrollView里的UITableView接收不到didSelectRowAtIndexPath调用消息. 问题原因应该是UITapGestureRecognizer吞掉了touch事件,导致didSelectRowAtIndexPath方法无法响应. 这篇文章里面说的将cancelsTouchesInView设置为NO没多大作用

UIScrollView不能响应touch事件的解决办法

UIScrollView本身事是不支持touch的,我们可以给她添加拓展 #import "UIScrollView+util.h" @implementation UIScrollView (util) -(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{ [[self nextResponder] touchesBegan:touches withEvent:event];

怎么解决UIScrollView把uitableviewcell的点击事件屏蔽了

[self.contentView addSubview:self.scrollView]; self.scrollView.userInteractionEnabled = NO; [self.contentView addGestureRecognizer:self.scrollView.panGestureRecognizer];