【发布时间】:2016-06-08 10:19:50
【问题描述】:
这个错误我有一些问题:
打开包装时意外发现 nil
调试器向我显示此错误的位置,但我不知道出了什么问题。错误出现在 UIView 动画块功能上。我在识别问题时遇到了问题。有一个代码:
override func viewDidLoad() {
NSNotificationCenter.defaultCenter().addObserver(self,
selector: #selector(playerItemDidReachEnd),
name: AVPlayerItemDidPlayToEndTimeNotification,
object: self.player?.currentItem);
}
func playerItemDidReachEnd(notification: NSNotification) {
self.player?.seekToTime(kCMTimeZero)
self.player?.play()
self.freeEffectAnimationImage.layer.removeAllAnimations()
self.freeEffectAnimationImage.center = self.beginingPoint
self.freeEffectAnimationImage.stopAnimating()
self.freeEffectAnimationImage.startAnimating()
if beginingPoint.x < 15 {
self.beginingPoint = CGPointMake(-CGRectGetWidth(freeEffectAnimationImage.frame), beginingPoint.y)
}
if endingPoint.x > self.view.frame.size.width - 15 {
self.endingPoint = CGPointMake(self.view.frame.size.width + CGRectGetWidth(freeEffectAnimationImage.frame), endingPoint.y)
}
UIView.animateWithDuration(self.animationDuration/2, delay:freeEffectDelay, options:UIViewAnimationOptions.Autoreverse, animations: {
self.freeEffectAnimationImage.center = self.endingPoint
}, completion: {
(success:Bool) in
if success {
self.freeEffectAnimationImage.center = self.beginingPoint
}
})
}
我会很高兴得到帮助:)
【问题讨论】:
-
你调试看看值是什么?
-
提供的代码没有显示
beginingPoint和endingPoint是如何初始化的,除非它们的值符合特定标准(if 块)。调用UIView.animation之前的值是多少 -
freeEffectAnimationImage、self.beginingPoint 或 self.endingPoint 是可选的吗?如果是这样,请尝试自我。 freeEffectAnimationImage?.center
-
哪一行导致错误?
-
你在哪里设置
freeEffectAnimationImage?有根据的猜测是当您收到通知时它尚未初始化......
标签: ios swift animation uiview