iOS 13分段控件:删除滑动手势以选择分段 [英] iOS 13 Segmented Control: Remove swipe gesture to select segment
问题描述
TLDR:如何在iOS 13上删除UISegmentedControl的滑动/平移手势识别器?
TLDR: How to remove the swipe/pan gesture recognizer for UISegmentedControl on iOS 13?
在iOS 13上,UISegmentedControl改变了很多.通常,更改是基于外观的.但是还有另一个功能更改使我的应用程序混乱.
Hi, on iOS 13, lots changed with UISegmentedControl. Mostly, the changes were appearance-based. But there is another functionality change that is messing up my app.
在iOS 13上,通过UISegmentedControls,您现在可以滑动/平移以更改选定的细分,而无需触摸要选择的细分.
On iOS 13, with UISegmentedControls, you can now swipe/pan to change the selected segment in addition to touching the segment you would like to select.
在我的应用程序中,基本上,我在滚动视图中嵌入了一个UISegmentedControl. UISegmentedControl对于屏幕而言太长,无法显示所有值,因此我创建了一个滚动视图,该滚动视图是屏幕的宽度,其内容宽度是UISegmentedControl的长度,并且用户要滑动不可见的段, 滚动视图"和分段的控制幻灯片.
In my app, I basically have a UISegmentedControl embedded in a scrollview. The UISegmentedControl is too long for the screen to display all of the values, so I created a scrollview that is the width of the screen, whose content width is the length of the UISegmentedControl, and to access the non-visible segments, the user swipes the "scrollview" and the segmented control slides.
这在iOS 13之前一直完美运行,现在,用户无法在拖动分段控件时滚动水平背景滚动视图,因为我假设滚动视图滚动识别器被新的滚动视图滑动覆盖以选择手势.
This worked perfectly up until iOS 13, and now, the user can't scroll the horizontal background scrollview while dragging on the segmented control because I am assuming the scrollview scroll recognizer is overridden by the new scrollview swipe to select gesture.
我甚至尝试递归地删除UISegmentedControl及其所有子视图的所有手势识别器,并且滑动以更改选择手势仍然有效...我被卡住了.
I have tried even removing ALL gesture recognizers for the UISegmentedControl and all of its subviews recursively, and the swipe to change selection gesture still works... I am stuck.
谢谢,如果问题不清楚,请告诉我
Thanks, let me know if the problem is unclear
推荐答案
我有一个类似的设置(在UIScrollView
bc中的UISegmentedControl
太长了,客户端不希望压缩内容以适合它).这对我有用(建立在Xcode 11.1上):
I have a similar setup (UISegmentedControl
inside a UIScrollView
bc it's too long and the client didn't want to compress the content to fit). This worked for me (Built on Xcode 11.1):
class NoSwipeSegmentedControl: UISegmentedControl {
override func gestureRecognizerShouldBegin(_ gestureRecognizer: UIGestureRecognizer) -> Bool {
return true
}
}
然后将我的UISegmentedControl
的类设置为该类.在我的应用程序中,这仅防止在UIScrollView
中嵌入的UISegmentedControl
对象上滑动选择手势.如果它不在UIScrollView
中,则没有任何不同的行为.这是有道理的,因为默认情况下gestureRecognizerShouldBegin()
返回true
.因此,为什么允许UIScrollView
优先使用滑动手势,我不知道.但希望能有所帮助.
Then set the class of my UISegmentedControl
to that. In my app this only prevents the swipe-to-select gesture on UISegmentedControl
objects embedded within a UIScrollView
. If it is not in a UIScrollView
nothing behaves any differently. Which makes sense because gestureRecognizerShouldBegin()
returns true
by default. So why this allows the UIScrollView
to take priority on the swipe gesture, I have no idea. But hope it helps.
这篇关于iOS 13分段控件:删除滑动手势以选择分段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!