我试图创建一个从右向左连续滚动图像的视图,从而有效地创建了无限滚动的背景。我使用彼此相邻的两个图像视图并使用UIView
设置为的动画来.Repeat
转换具有负水平偏移的帧。(下面的代码)
效果很好!在尝试在导航控制器中进行边缘轻扫之前,动画将冻结:
我的代码如下所示:
class ScrollingImageView: UIView {
required init?(coder aDecoder: NSCoder) { fatalError() }
let imageView = UIImageView()
let imageView2 = UIImageView()
override init(frame: CGRect) {
super.init(frame: frame)
imageView.image = UIImage(named: "mario")
imageView2.image = UIImage(named: "mario")
imageView.frame = bounds
imageView2.frame = CGRectOffset(bounds, bounds.width, 0)
addSubview(imageView)
addSubview(imageView2)
}
func play() {
UIView.animateWithDuration(5, delay: 0, options: [.Repeat, .CurveLinear], animations: {
self.imageView.frame = CGRectOffset(self.imageView.frame, -self.bounds.width, 0)
self.imageView2.frame = CGRectOffset(self.imageView2.frame, -self.bounds.width, 0)
}, completion: nil)
}
}
为什么当交互开始时动画会停止?我想它有什么做的交互手势在设定的速度CALayer
到零。有没有办法让这个动画继续播放?
正确地说,您使用的是交互式手势。它是如何工作的?它冻结动画(图层speed
为零)并更改其“帧”(图层timeOffset
)以匹配手势的当前位置。
要解决此问题,您也许可以将动画放到另一个图层中,尽管我对此不确定。我敢肯定,这样会努力将自己实现整个自定义转换交互-不使用UIPercentDrivenInteractiveTransition(其中冻结动画),但定位自己的观点作为过渡收益。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句