【发布时间】:2016-03-23 00:39:07
【问题描述】:
我正在制作一个小动画,当该动画结束时,我希望应用程序自动推送下一个ViewController。好吧,ViewController 被连续推了 8 次!真是太疯狂了。
代码如下:
if CGRectIntersectsRect(whichButton.frame, targetZoneImgView.frame) {
panGesture.cancelsTouchesInView = true
let buttonSnapX = UIScreen.mainScreen().bounds.width / 2.0 - 35.0
let buttonSnapY = UIScreen.mainScreen().bounds.height - 122.0
UIView.animateWithDuration(0.75, delay: 0.0,
usingSpringWithDamping: 0.1,
initialSpringVelocity: 0.0,
options: UIViewAnimationOptions.CurveEaseOut,
animations: {
myButton.frame.origin.x = buttonSnapX
myButton.frame.origin.y = buttonSnapY
}, completion: { (finished: Bool) -> Void in
print("Animation done!")
let storyBoard : UIStoryboard = UIStoryboard(name: "Main", bundle:nil)
let coursesScreen = storyBoard.instantiateViewControllerWithIdentifier("coursesScreen") as! CoursesVC
self.navigationController!.pushViewController(coursesScreen, animated: true)
}
)
print("Animation done!") 语句也会连续触发 8-9 次,因此它与我推送 ViewController 的事实无关。我取出了ViewController 代码 - 它仍在发生。
基本上,我在completion 中输入的任何东西都会连续发射很多次。
世界上发生了什么事?
【问题讨论】:
-
我以前从未亲自遇到过这种情况,但是如果您不使用弹簧动画,请看看它是否会停止。 (只是一个经典的
animateWithDuration:animations:completion:)如果能解决它,那么我敢打赌苹果在他们的春季动画中做了一些非常愚蠢的事情!
标签: ios animation completionhandler animatewithduration