Cancel current UIScrollView touch(取消当前 UIScrollView 触摸)
问题描述
我有一个带有几个子视图的 UIScrollView
等等.我也是scrollView的delegate
,并实现了- (void)scrollViewDidScroll:(UIScrollView *)scrollView
.在我的卷轴下面有另一个视图.
I have an UIScrollView
with a few subviews and so on. I am also the scrollView's delegate
and have implemented the - (void)scrollViewDidScroll:(UIScrollView *)scrollView
. Underneath my scroll there is another view.
如果滚动视图的 contentOffset
在 x 轴上低于 50px,我想显示该视图,重置"滚动视图的 contentOffset
并取消当前的滚动视图手势,以便用户不会在新视图出现时操作其内容.
I want to show that view if the scrollView's contentOffset
goes under 50px on x axis, "reset" scrollView's contentOffset
and cancel the current scrollView gesture so that the user wont manipulate its content when the new view appears.
我已经实现了这样的方法:
I have implemented the method like so:
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
if (scrollView.contentOffset.x < -50)
{
scrollView.contentOffset = CGPointZero;
[self showBackView];
//here I want to cancel the current touch on the scrollview since it keeps scrolling if I drag my finger
}
}
我曾尝试将 userInteractionEnabled
属性设置为 NO
但只有在触摸结束后才会生效.而且我尝试了许多其他属性,但似乎都没有.
I have tried to set the userInteractionEnabled
property to NO
but it takes effect only after the touch has ended. And I have tried a bunch of other properties but none seems to work.
我该如何解决这个问题?
How can I fix this?
推荐答案
尝试禁用滚动视图的 panGestureRecognizer
(然后重新启用它).这将取消识别器的当前会话:
Try disabling the panGestureRecognizer
for the scroll view (and then reenabling it). This will cancel the current session of the recogniser:
self.scrollView.panGestureRecognizer.enabled = NO;
self.scrollView.panGestureRecognizer.enabled = YES;
斯威夫特
self.scrollView.panGestureRecognizer.isEnabled = false
self.scrollView.panGestureRecognizer.isEnabled = true
这篇关于取消当前 UIScrollView 触摸的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:取消当前 UIScrollView 触摸


基础教程推荐
- navigator.geolocation.getCurrentPosition 在 Android 浏览器上 2022-01-01
- libGDX 从精灵或纹理中获取像素颜色 2022-01-01
- iOS4 创建后台定时器 2022-01-01
- 通过重定向链接在 Google Play 中打开应用 2022-01-01
- iPhone - 获取给定地点/时区的当前日期和时间并将其与同一地点的另一个日期/时间进行比较的正确方法 2022-01-01
- Cocos2d iPhone 非矩形精灵触摸检测 2022-01-01
- 如何从 logcat 中删除旧数据? 2022-01-01
- NSString intValue 不能用于检索电话号码 2022-01-01
- AdMob 广告未在模拟器中显示 2022-01-01
- Android:getLastKnownLocation(LocationManager.NETWORK_PROVIDER 2022-01-01