gpt4 book ai didi

ios - UILongPressGestureRecognizer 在状态改变时继续动画

转载 作者:搜寻专家 更新时间:2023-11-01 05:37:20 26 4
gpt4 key购买 nike

我在 UIImageView 上添加了一个 UILongPressGestureRecognizer。它的目的是如果用户按下图像动画应该开始。这是完美的。但是一旦用户稍微移动他的手指,动画就会停止。我知道发生这种情况是因为状态发生了变化。但是我想继续动画,只有当用户从图像上移开他的手指时才停止。

到目前为止,我添加手势识别器的代码是

let tapGestureRecognizer = UILongPressGestureRecognizer(target:self, action:Selector("imageTapped:"))
tapGestureRecognizer.minimumPressDuration = 0
barcodeImage.userInteractionEnabled = true
barcodeImage.addGestureRecognizer(tapGestureRecognizer)

动画的代码是

func imageTapped(gesture: UILongPressGestureRecognizer)
{
let animation : CATransition = CATransition()
animation.delegate = self
animation.duration = 2.5
animation.repeatCount = Float.infinity
animation.type = "rippleEffect"
if(gesture.state == UIGestureRecognizerState.Ended){
logger.log("press ended");
// and stop animation
barcodeImage.layer.removeAllAnimations()
}else{
logger.log("show animation")
barcodeImage.layer.addAnimation(animation, forKey: nil)
}
}

当状态改变时如何继续动画?

最佳答案

barcodeImage.userInteractionEnabled = true

override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {

if (touches.first?.view == barcodeImage) {
print("show animation")
}
}

override func touchesEnded(touches: Set<UITouch>, withEvent event: UIEvent?) {
print("removeAllAnimations")
}

override func touchesCancelled(touches: Set<UITouch>?, withEvent event: UIEvent?) {
print("removeAllAnimations")
}

关于ios - UILongPressGestureRecognizer 在状态改变时继续动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35430192/

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