防止 UIPageViewController 的滑动影响 UISlider [英] Prevent UIPageViewController's swipe from affecting a UISlider

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

问题描述

我在其他领域看到过这个问题,但没有一个答案适用于我的情况.我有一个 UIPageViewController,它有一个包含 UISlider 的子视图控制器.

I've seen this question asked in other areas but none of the answers work in my case. I have a UIPageViewController that has a child view controller containing a UISlider.

当您尝试移动滑块时,它会激活页面视图控制器的滚动.您必须点按,在滑块圆圈上暂停,然后移动.

When you go to try to move the slider, it activates the page view controller's scrolling instead. You have to tap, pause on the slider circle, and then move.

UIPageViewController 设置为滚动类型,因此没有设置gestureRecognizers.(标题说明仅当过渡样式为‘UIPageViewControllerTransitionStylePageCurl’时才填充").因此,我什至无法正确访问手势.

The UIPageViewController is set to the scroll type, and thus the gestureRecognizers are not set. (The header states "Only populated if transition style is 'UIPageViewControllerTransitionStylePageCurl'"). Thus I can't even get proper access to the gestures.

我尝试了几种方法来防止 UIPageViewController 影响滑块,但都无济于事.我试过了:1)走子树并将UIScrollView的平移手势委托设置为我自己(这会导致崩溃)2) 在顶部添加我自己的手势,并检查 y 值.这将阻止滑动,但它也会吃掉点击和移动,因此滑块实际上不会按预期改变3) 使用自定义手势实现自定义滑块.问题是我无法匹配更改滑块的平移手势与默认设置相同.由于您必须自己实现平移并调整位置,因此很难匹配真实的行为.

I've tried several things to prevent the UIPageViewController from affecting the slider, but to no avail. I've tried: 1) walking the child subtree and setting the UIScrollView's pan gesture delegate to myself (this causes a crash) 2) Add my own gesture on top, and check the y value. This will prevent the swipe, but it also eats the tap and move so the slider doesn't actually change as expected 3) Implemented a custom slider with custom gestures. The problem is I can't match the pan gesture changing the slider in the same was as the default. Since you have to implement the pan and adjust the positions yourself, it's difficult to match the real behavior.

这些方法中没有一个对我有效.有没有人能够解决这个问题?我能想到的唯一解决方案是防止一起滚动,添加左/右按钮,并相应地以编程方式转换页面.

None of these methods actually works for me. Has anyone been able to solve this? The only solution I can think of is to prevent scrolling all together, add left/right buttons, and programmatically transition pages accordingly.

推荐答案

您可以将 UIPanGestureRecognizer 添加到滑块,并将 cancelsTouchesInView 属性设置为 false 避免 UIPageViewController 在拖动滑块时滑动:

You can add an UIPanGestureRecognizer to the slider with the cancelsTouchesInView attribute to false to avoid the UIPageViewController to swipe when you drag the slider :

let panGesture = UIPanGestureRecognizer()
panGesture.cancelsTouchesInView = false
yourSlider.addGestureRecognizer(panGesture)

这篇关于防止 UIPageViewController 的滑动影响 UISlider的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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