【发布时间】:2015-01-22 10:18:55
【问题描述】:
我正在使用这些(代码块 1 和 2)将带有动画的 UIScrollView 从开始移动到我的结束点 (在本例中,x:0 到 1000)
代码块 1:
UIScrollView.animateWithDuration(Double(5), delay: 1, options: (UIViewAnimationOptions.AllowUserInteraction | UIViewAnimationOptions.CurveLinear | UIViewAnimationOptions.BeginFromCurrentState),
animations: {
self.myScrollView.contentOffset = CGPointMake(1000, 0)
},
completion: {
finished in
if(finished)
{
}
})
代码块 2:
UIView.animateWithDuration ...
问题是不能在当前x点暂停。
我已经尝试过了,但对我不起作用。
- 导入 QuartzCore 框架
- self.myScrollView.layer.beginTime = 0.0 完成
CATransaction.begin() 和 CATransaction.commit()
self.myScrollView.layer.removeAllAnimations()。这会完全停止动画,然后 UIScrollView 将到达 endPoint(到 x:1000)
另外animateWithDuration是取消scrollViewDidScroll,所以无法获取当前位置。另外,同样的原因,在暂停功能中无法获取当前位置。
func scrollViewDidScroll(scrollView: UIScrollView)
{
scrollView.bounds.origin.x
var pos:CGPoint = self.layer.presentationLayer().bounds.origin
}
func StopSlidingByBeginDragging()
{
CATransaction.begin()
self.myScrollView.layer.removeAllAnimations()
CATransaction.commit()
}
基本上,当我手动触摸或滚动 UIScrollView 时,我需要暂停它应该暂停然后恢复。我发现这个动画是滑动动画,也许你可以提出一些不同的建议。
谢谢
【问题讨论】:
标签: ios swift uiscrollview uiviewanimation