2016-09-25 105 views
1

在线几个示例后,我试图为MKAnnotationView创建动画。我已经放置在init下面的代码()我MKAnnotationView子类:尝试动画MKAnnotationView时应用程序崩溃

UIView.animate(withDuration: 10.0, delay: 0.0, options: .repeat, animations: {    
    UIView.addKeyframe(withRelativeStartTime: 0.0, relativeDuration: 0.5, animations: { 
     self.frame = biggerFrame 
    }) 

    UIView.addKeyframe(withRelativeStartTime: 0.5, relativeDuration: 0.5, animations: { 
     self.frame = originalFrame 
     }) 
}, completion: nil) 

只要注解视图被添加到地图,应用程序崩溃,但以下情况除外:

2016-09-25 19:32:58.655 MyApp 42[62332:4524529] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '+[UIView addKeyframeWithStartTime:duration:animations:] must be called inside the animations block of +[UIView animateKeyframesWithDuration:delay:options:animations:completion:]' 

任何想法我做错了什么?

谢谢!

回答

1

由于控制台建议,你应该使用:

UIView.animateKeyframes(withDuration: TimeInterval, delay: TimeInterval, options: UIViewKeyframeAnimationOptions, animations: { 
    your animation here 
    }, completion: nil) 

,而不是:)

目前,您正在使用的UIView。 animate(withDuration:delay:Option:animations:Completion :)

+0

D'oh!我想我应该在将来更仔细地阅读错误信息。 –

相关问题