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?