我使用UIScrollView
来显示一些图像。我发现滑动手势和平移手势都可以。一次只能使摇动手势起作用吗?
我尝试了以下代码:
for gestureRecognizer in scrollView.gestureRecognizers ?? [] {
if gestureRecognizer is UISwipeGestureRecognizer) {
gestureRecognizer.isEnabled = false
}
}
它不起作用。我打印scrollView.gestureRecognizers!
,得到手势列表:
UIScrollViewDelayedTouchesBeganGestureRecognizer
UIScrollViewPanGestureRecognizer
_UIDragAutoScrollGestureRecognizer
UIScrollViewPagingSwipeGestureRecognizer
我尝试了UIScrollViewPagingSwipeGestureRecognizer
:
if gestureRecognizer is UIScrollViewPagingSwipeGestureRecognizer) {
gestureRecognizer.isEnabled = false
}
上面写着Use of undeclared type 'UIScrollViewPagingSwipeGestureRecognizer'
。
答案 0 :(得分:0)
如果我对您的理解正确...也许您可以使用以下UIScrollViewDelegate
方法:
func scrollViewWillEndDragging(_ scrollView: UIScrollView, withVelocity velocity: CGPoint, targetContentOffset: UnsafeMutablePointer<CGPoint>) {
targetContentOffset.pointee = scrollView.contentOffset
}