【发布时间】:2018-07-19 05:09:03
【问题描述】:
我正在为视图设置动画以在用户平移屏幕时移动。我保留了一个阈值,之后视图将动画到默认位置。
目前的问题是在持续时间之前调用了将视图重置到某个位置的动画方法的完成处理程序。动画似乎是突然发生的,而不是持续一段时间。
// Pan gesture selector method
@objc func panAction(for panGesture: UIPanGestureRecognizer) {
switch panGesture.state {
case .began:
//Began code
case changed:
if (condition) {
print("IF")
//Change constraint constant of customView
animate(view: customView)
} else if (condition) {
print("ELSE IF")
//Change constraint constant of customView
animate(view: customView)
} else {
//Change constraint constant of customView
print("ELSE")
view.layoutIfNeeded()
}
case .ended:
//Ended code
default:
break
}
}
动画方法:
func animate(view: UIView) {
UIView.animate(withDuration: 3, delay: 0, options: .curveEaseOut, animations: {
view.layoutIfNeeded()
}, completion: { (finished) in
if finished {
flag = false
}
})
}
立即设置标志,而不是在 3 秒后设置。
平移和越过阈值时得到的 o/p。
否则
否则
否则
否则
如果
编辑:我是个白痴。我没有在 superView 上调用layoutIfNeeded()。
【问题讨论】:
-
请添加您有问题的代码
-
我正在编辑我的问题。请立即检查。
标签: ios swift uipangesturerecognizer