gpt4 book ai didi

ios - GestureRecogniser 没有响应

转载 作者:行者123 更新时间:2023-11-28 15:55:56 24 4
gpt4 key购买 nike

初学者 - 下面的代码在 TouchesBegan 函数中运行良好。但不适用于 GestureRecongnizer(滑动或点击)。手势识别器似乎根本没有响应。

我正在研究 swift 2 和 xcode 7.3

override func viewDidLoad()
{ ...
let SwipeUp = UISwipeGestureRecognizer(target: self, action:#selector(ViewController.Dragged(_:)))
SwipeUp.direction = UISwipeGestureRecognizerDirection.Up
self.egg.addGestureRecognizer(SwipeUp)
}
func Dragged(gesture: UIGestureRecognizer)
{
UIView.animateWithDuration(0.4, delay: 1.0, options: .CurveEaseOut, animations: {
let eggFrame = self.egg.frame
eggFrame.origin.y -= 700
self.egg.frame = eggFrame
}, completion: { finished in print("done!") }
}

最佳答案

您需要保持对 UIGestureRecognizer 的强引用。

var swipeUp: UISwipeGestureRecognizer!

override func viewDidLoad() {
swipeUp = UISwipeGestureRecognizer(target: self, action:#selector(ViewController.Dragged(_:)))
swipeUp.direction = UISwipeGestureRecognizerDirection.Up
self.egg.addGestureRecognizer(swipeUp)
}

func Dragged(gesture: UIGestureRecognizer) {
UIView.animateWithDuration(0.4, delay: 1.0, options: .CurveEaseOut, animations: {
let eggFrame = self.egg.frame
eggFrame.origin.y -= 700
self.egg.frame = eggFrame
}, completion: { finished in print("done!") }
}

关于ios - GestureRecogniser 没有响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41744512/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com