向右滑动以关闭边缘大小
Posted
技术标签:
【中文标题】向右滑动以关闭边缘大小【英文标题】:Swipe right to dismiss edge size 【发布时间】:2019-12-26 00:16:09 【问题描述】:是否可以增加 UINavigationController 的边缘大小interactivePopGestureRecognizer
以响应用户触摸?
即是否可以从屏幕中间向右滑动以移动和弹出当前顶部 Viewcontroller 与从左屏幕边缘相同的方式?
【问题讨论】:
你可以试试 PAN 手势识别器 【参考方案1】:
override func viewDidLoad()
super.viewDidLoad()
let swipeRight = UISwipeGestureRecognizer(target: self, action: #selector(respondToSwipeGesture))
swipeRight.direction = .right
self.view.addGestureRecognizer(swipeRight)
let swipeLeft = UISwipeGestureRecognizer(target: self, action: #selector(respondToSwipeGesture))
swipeLeft.direction = .left
self.view.addGestureRecognizer(swipeLeft)
// you can track all direction swipe like below, and to do that first you have to add gesture in the view you want to track.
@objc func respondToSwipeGesture(gesture: UIGestureRecognizer)
if let swipeGesture = gesture as? UISwipeGestureRecognizer
switch swipeGesture.direction
case .right:
// push pop here
print("Swiped right")
case .down:
print("Swiped down")
case .left:
// push pop here
print("Swiped left")
case .up:
print("Swiped up")
default:
break
【讨论】:
感谢您的回答,但主要问题是如何使用与默认滑动关闭相同的动画来处理这种从左到右的手势。将视图边缘移动到触摸位置并根据触摸位置和速度关闭或移回视图。【参考方案2】:最后,找到了使用这个库增加边缘触摸尺寸的解决方案:SwipeTransition
【讨论】:
以上是关于向右滑动以关闭边缘大小的主要内容,如果未能解决你的问题,请参考以下文章
在 iOS7 中边缘滑动时,使键盘与 UIView 同步动画