为什么重复UIView动画冻结边缘滑动?

时间:2016-07-19 19:08:49

标签: ios swift core-animation

我正在尝试制作一个视图,从右到左连续滚动图像,有效地创建无限滚动的背景。我使用两个彼此相邻的图像视图构建了这个视图,并使用设置为UIView的{​​{1}}动画来转换具有负水平偏移的帧。 (以下代码)

效果很好!直到我在导航控制器中尝试边缘滑动,此时动画会冻结:

animation freezing on edge swipe

我的代码如下:

.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) } } 的速度设置为零。有没有办法让这个动画继续播放?

1 个答案:

答案 0 :(得分:1)

正如你正确地说,你正在使用交互式手势。它是如何工作的?它会冻结动画(图层speed为零)并更改其“框架”(图层timeOffset)以匹配手势的当前位置。

要解决这个问题,您可以将动画放入不同的层,但我不确定。我确定工作的方式是自己实现整个自定义转换交互 - 使用UIPercentDrivenInteractiveTransition(冻结动画),但将视图定位为过渡进行了。