[英]Multiple swift animations in parallel not working
i have this code animating some elements (total of 3) in a view. 我有这段代码动画视图中的某些元素(共3个)。
for element in elements{
if element.value != radians {
UIView.animateWithDuration(0.99,
animations: {
element.transform = CGAffineTransformMakeRotation(CGFloat(radians))
}, completion: {
finished in
element.value = radians
})
}
}
When 2 or more elements should be animated (UIView.animateWithDuration is called 2 or more times one after another), only one is animating and the animation is quite choppy. 当应为2个或更多元素进行动画处理(UIView.animateWithDuration被一个接一个地调用2个或更多)时,只有一个动画是动画,并且动画非常不稳定。 I know that i should write everything in the animation block, but i can't figure out how to do it. 我知道我应该在动画块中编写所有内容,但是我不知道该怎么做。 Please help me. 请帮我。
Just put the for loop inside the animation block. 只需将for循环放入动画块中即可。
UIView.animateWithDuration(0.99,
animations: {
for element in elements {
if element.value != radians {
element.transform = CGAffineTransformMakeRotation(CGFloat(radians))
}
}
}, completion: { _ in
element.value = radians
})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.