iOS 13 Segmented Control: Remove swipe gesture to select segment

后端 未结 3 772
隐瞒了意图╮
隐瞒了意图╮ 2021-01-04 18:16

TLDR: How to remove the swipe/pan gesture recognizer for UISegmentedControl on iOS 13?

Hi, on iOS 13, lots changed with UISegmentedControl. Mostly, the changes were

3条回答
  •  醉话见心
    2021-01-04 19:16

    Using this code allows the segmented control to still be swiped UNLESS it's embedded in a UIScrollView. This is the smallest tradeoff in functionality in my opinion

    final class NoSwipeSegmentedControl: UISegmentedControl {
    
        override func gestureRecognizerShouldBegin(_ gestureRecognizer: UIGestureRecognizer) -> Bool {
            guard type(of: gestureRecognizer).description() != "UIScrollViewPanGestureRecognizer" else {
                return true
            }
            return super.gestureRecognizerShouldBegin(gestureRecognizer)
        }
    
    }
    

提交回复
热议问题