简体   繁体   English

触摸并按住然后滑动时,“滚动视图”不会滚动

[英]Scroll View doesn't scroll when touching and holding then swiping

I have UIScrollView with other UIView elements inside. 我有UIScrollView和其他UIView元素在里面。 My other UIView elements are mostly segmented controls. 我的其他UIView元素大多是分段控件。 If I click on a UISegmentedControl and hold for a second and then try to scroll, then no scrolling happens. 如果单击UISegmentedControl并保持一秒钟,然后尝试滚动,则不会发生滚动。 I can only scroll when my finger touches and swipes immediately. 我只能在手指立即触摸和滑动时滚动。 I checked other iOS applications such as mail. 我检查了其他iOS应用程序,例如邮件。 The behavior was that you touch and hold on a mail, then it's highlighted, but as soon as finger moves away, the scrolling happens and highlighting is undone. 行为是您触摸并按住邮件,然后将其突出显示,但是一旦手指移开,就会发生滚动,并且突出显示被取消。 How can I implement this behavior? 如何执行此行为?

You can follow one of these steps: 您可以执行以下步骤之一:

  1. If you are using UISegmentedControl over you UIScrollView, instead of that, add the UISegmentedControl over your controller's view. 如果要在UIScrollView上使用UISegmentedControl,请改用UISegmentedControl在控制器的视图上。

  2. If you want to use UISegmentedControl over your scrollView, then you have to create a custom scrollView by creating a subclass of UIScrollView and use an image view instead of UISegmentedControl adding the labels which can act as the segments. 如果要在您的scrollView上使用UISegmentedControl,则必须通过创建UIScrollView的子类来创建自定义的scrollView,并使用图像视图代替UISegmentedControl来添加可充当分段的标签。 This is because your UISegmentControl itself is a touch handler and it breaks the UIResponder chain. 这是因为您的UISegmentControl本身是一个触摸处理程序,并且中断了UIResponder链。 So, the scrolling might face issues during the touch events. 因此,在触摸事件期间滚动可能会遇到问题。

Please let me know if any of these works. 如果有任何一项,请告诉我。 Thanks :) 谢谢 :)

The issue was the property of UIScrollView. 问题是UIScrollView的属性。 The property canCancelContentTouches was set to NO. 属性canCancelContentTouches设置为NO。 Because of that, touch events were handled by subviews of scroll view and swiping didn't cause scrolling. 因此,触摸事件由滚动视图的子视图处理,并且滑动不会导致滚动。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM