我做了一个简单的项目,带有滑动手势识别器和动画。我让我的标签移动,每 3 秒增加一次。每次滑动我都需要减少数字。我的手势识别器对象与标签绑定,即它仅适用于标签边界。当 prog 在没有动画的情况下工作时一切正常,但是当它被动画并移动时,我的手势识别器什么都不做。如何使手势识别器与动画同时工作,即在动画响应我的滑动时。需要帮忙。
`
@IBOutlet weak var label1: UILabel!
var number : Int = 0
var timer = Timer()
@IBAction func label1SwipeRight(_ sender: UISwipeGestureRecognizer) {
number += 1
label1.text = String(number)
}
func animate1() {
UIView.animate(withDuration: 4.0, delay: 0.0, options: .allowUserInteraction, animations: {
let num1 : CGFloat = CGFloat(arc4random_uniform(667))
let num2 : CGFloat = CGFloat(arc4random_uniform(375))
self.label1.frame.origin.y = num1
self.label1.frame.origin.x = num2
}, completion: {(bool) in
self.animate1()
print("Animation1 completed")
})
}
func timerExample() {
Timer.scheduledTimer(timeInterval: 4, target: self, selector: …
Run Code Online (Sandbox Code Playgroud)