當我在viewDidLoad()方法內添加以下代碼的時候發現程序運行時不會有動畫過度效果,而是直接跳到了最后。
let x = (self.view.bounds.size.width - 268) / 2 scanImage.frame = CGRectMake(x, 106, 268, 2) scanImage.contentMode = UIViewContentMode.ScaleAspectFill self.view.addSubview(scanImage) UIView.animateWithDuration(2, delay: 0, options: UIViewAnimationOptions.Repeat, animations: { () -> Void in self.scanImage.frame = CGRectMake(x,372, 268, 2) }, completion: nil)
通過度娘后有網友說要把該代碼塊放到viewDidAppear(animated: Bool)方法內,試以一下果然有動畫效果了。這到底是為什么啊?who can tell me why?