当我向上滑动时,我有一个向上移动的图层,当我向下滑动时,同一层又向下移动。
向上滑动时,我不希望用户向下滑动以激活该动画,直到向上滑动动画完成为止,反之亦然。
我该如何完成?我尝试使用“ isEnabled”禁用滑动手势,但没有骰子。其他一些类似的问题也提供了很久以前的答案,并且语法也有很大不同。我正在使用最新版本的xcode。
我对xcode还是比较陌生,所以请原谅我对此方面缺乏信息。如果您有任何问题,请告诉我。
谢谢!
答案 0 :(得分:0)
可以通过添加布尔变量IF语句以及DispatchQueue函数来解决此问题,以防止在当前动画完成之前发生另一个动画。
请看下面,如果有帮助,请投票:)
import UIKit
var animation_active = false
let animation_duration = 2 //For easy maintenance
func swipe_down() {
if animation_active == false {
animation_active == true
//Animation code goes here. Variable 'animation_active' should be used when performing the animation for easy matinence
DispatchQueue.main.asyncAfter(deadline: .now() + .seconds(animation_duration), execute: {
animation_active = false
})
}
}
func swipe_up() { //This is exactly the same as swipe_up. Yet it will prevent the swipe animation from occuring when the swipe down animation is occuruing thanks to the variable 'animation_active'
if animation_active == false {
animation_active == true
//Animation code goes here. Variable 'animation_active' should be used when performing the animation for easy matinence
DispatchQueue.main.asyncAfter(deadline: .now() + .seconds(animation_duration), execute: {
animation_active = false
})
}
}