我在 UIScrollview 中有一个(垂直的)UISlider。我希望能够更改 slider 的值,并且在不抬起手指的情况下向左或向右滚动 ScrollView 。
期望的行为:
在垂直的 UISlider 中向下触摸,然后用手指向左或向右拖动会导致 ScrollView 滚动
实际行为:
在垂直 UISlider 内向下触摸,然后用手指向左或向右拖动会导致 UIScrollview 中没有移动。在 UISlider 的外部下触摸,然后拖动将按预期滚动 ScrollView
UIView 有一个名为 exclusiveTouch 的属性,它似乎与我的问题有关。我尝试将其设置为 NO,但没有成功。
那么,如何设置我的 UISliders 以便它们下面的 ScrollView 响应 UISliders 内部发起的触摸?
最佳答案
您是否尝试过子类化 UIScrollView
并实现 - (BOOL)touchesShouldCancelInContentView:(UIView *)view
?根据 Apple 文档:
// called before scrolling begins if touches have already been delivered to a subview of the scroll view. if it returns NO the touches will continue to be delivered to the subview and scrolling will not occur
// not called if canCancelContentTouches is NO. default returns YES if view isn't a UIControl
如果您在 view
是您的 UISlider
时简单地返回 NO
,这可能会做您想要的,假设您的 UIScrollView
仅水平滚动。如果这不起作用,您可能必须为您的两者进行自定义触摸处理(即覆盖 touchesBegan:withEvent:
、touchesChanged:withEvent:
等) UIScrollView
和您的 UISlider
。
关于objective-c - 触摸 UISlider 会阻止 UIScrollView 的滚动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11004419/