ios – UIRotationGestureRecognizer多次激活Swift
发布时间:2020-12-14 17:35:35 所属栏目:百科 来源:网络整理
导读:使用UIRotationGestureRecognizer时,会识别旋转,但会多次触发操作.这是我的代码: override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view,typically from a nib. let rotation = UIRotationGestureRecogniz
使用UIRotationGestureRecognizer时,会识别旋转,但会多次触发操作.这是我的代码:
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) 我希望你刚收到Began和End州. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |