尝试动画MKAnnotationView时应用程序崩溃

时间:2016-09-25 19:54:42

标签: ios swift uiview mapkit uiviewanimation

在网上举几个例子后,我试图为MKAnnotationView设置动画。我已将以下代码放在我的MKAnnotationView子类的init()中:

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 个答案:

答案 0 :(得分:1)

正如控制台建议的那样,你应该使用:

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

代替:)

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