【发布时间】:2020-08-19 07:51:07
【问题描述】:
我在我的视图上设置 UIPanGestureRecognizer,我的代码在 13.0 之前的 iOS 版本上工作,但在 13.0 中它不起作用,而且我调试了我的代码,它运行得很好,但它没有翻译任何东西。
以下是在我的视图上设置 UIPanGestureRecognizer 的方式,即 viewContentBG
let recognizer = UIPanGestureRecognizer(target: self, action: #selector(self.handlePan(recognizer:)))
recognizer.delegate = self
viewContentBG.isUserInteractionEnabled = true
viewContentBG.addGestureRecognizer( recognizer)
现在在设置委托后,我正在调用我的识别器。但以下代码不适用于 iOS 13,但它在 13.0 之前的所有版本上都可以正常工作
if recognizer.state == .changed {
let velocity = recognizer.velocity(in: self.viewContentBG)
translation = recognizer.translation(in: self.viewContentBG)
if( (velocity.x > 0 && self.viewContentBG.frame.origin.x < self.viewContentBG.frame.size.width / 3.0)){
let movedPoint = CGPoint(x: originalCenter.x+translation.x, y: originalCenter.y)
self.viewContentBG.center = movedPoint
self.btnLeftAction1.frame.origin.x = 0
self.btnLeftAction1.frame.size.width = 0
self.btnLeftAction2.frame.origin.x = 0
self.btnLeftAction2.frame.size.width = self.viewContentBG.frame.origin.x
}
从上面的代码中,以下几行是最重要的,但它不适用于 13.0 和更高版本。视图(viewContentBg)得到 有时从错误的方向移动一点,然后回到原来的位置 原来的位置,有时候真的不动一点。
let movedPoint = CGPoint(x: originalCenter.x+translation.x, y: originalCenter.y)
self.viewContentBG.center = movedPoint
我怀疑 13.0 及更高版本中存在某种新限制 使用 UIPanGestureRecognizer 的 iOS 版本,但我真的不 知道导致它不起作用的主要原因是什么 正确。请帮助我,我陷入了困境。及其主要特征 我的应用程序。 :(
【问题讨论】:
标签: ios swift iphone xcode ios13