触摸UISlider可以防止滚动UIScrollView [英] Touch on UISlider prevents scrolling of UIScrollView

查看:74
本文介绍了触摸UISlider可以防止滚动UIScrollView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在UIScrollview中有一个(垂直)UISlider。我希望能够更改滑块的值,并且在不松开手指的情况下向左或向右滚动滚动视图。

I have a (vertical) UISlider inside a UIScrollview. I'd like to be able to change the value of the slider, and, without lifting my finger, scroll the scrollview left or right.

所需的行为:

在垂直UISlider内向下触摸,然后用手指向左或向右拖动会导致滚动视图滚动

Touch down inside vertical UISlider, followed by a finger drag left or right causes the scrollview to scroll

实际行为:

触摸在垂直UISlider中向下滑动,然后向左或向右拖动手指将不会导致UIScrollview中移动。按下UISlider的外部,然后拖动鼠标,将按预期方式滚动滚动视图。

Touch down inside vertical UISlider, followed by a finger drag left or right causes no movement in UIScrollview. A touch down outside the UISlider followed by a drag will scroll the scrollview as expected

UIView具有一个名为ExclusiveTouch的属性,看起来好像与我的问题有关。我尝试将其设置为否,但没有运气。

UIView has a property called exclusiveTouch which seems as if it might be related to my problem. I tried setting it to NO, with no luck.

那么,如何设置UISliders,使其下方的滚动视图能够响应UISliders内部产生的触摸?

So, how can is set up my UISliders so that the scrollview beneath them will respond to touches which originate inside the UISliders?

推荐答案

您是否尝试将 UIScrollView 子类化并实现-(BOOL)touchesShouldCancelInContentView:(UIView * )查看?根据Apple文档:

Have you tried subclassing UIScrollView and implementing - (BOOL)touchesShouldCancelInContentView:(UIView *)view? According to the Apple documentation:

// 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

如果您只是返回 NO 如果视图是您的 UISlider ,则此可以您想要的,假设您的 UIScrollView 仅水平滚动。如果这不起作用,则可能必须进行自定义触摸处理(即,覆盖 touchesBegan:withEvent: touchesChanged:withEvent:等)同时用于 UIScrollView UISlider

If you simply return NO if the view is your UISlider, this may do what you want, assuming your UIScrollView only scrolls horizontally. If this doesn't work, you likely will have to do custom touch handling (ie. overriding touchesBegan:withEvent:, touchesChanged:withEvent:, etc.) for both your UIScrollView and your UISlider.

这篇关于触摸UISlider可以防止滚动UIScrollView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆