gpt4 book ai didi

ios - UIRotationGestureRecognizer 多次激活 Swift

转载 作者:搜寻专家 更新时间:2023-10-31 19:29:31 26 4
gpt4 key购买 nike

当使用 UIRotationGestureRecognizer 时,旋转被识别但它会多次触发 Action 。这是我的代码:

override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
let rotation = UIRotationGestureRecognizer(target: self, action: #selector(ViewController.lol))
self.view.addGestureRecognizer(rotation)
}

func lol() {
print ("hi")
UIView.animateWithDuration(5.0, animations: {
let currTransform = self.view.transform
let newTransform = CGAffineTransformConcat(currTransform, CGAffineTransformMakeRotation(CGFloat(M_PI)))
self.view.transform = newTransform

})
}

最佳答案

查看 UIRotationGestureRecognizer 的状态。

let rotation = UIRotationGestureRecognizer(target: self, action: #selector(ViewController.lol(_:)))

func lol(sender: UIRotationGestureRecognizer) {
print(sender.state)

我希望您刚刚收到 BeganEnd 状态。

关于ios - UIRotationGestureRecognizer 多次激活 Swift,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38812600/

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