期间复位的UIScrollView contentOffset我有一个UIScrollView
被垂直coreAnimation滚动如下:CoreAnimation
- (void) scrollAnimation
{
CGRect bounds = scrollview.bounds;
CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"bounds"];
animation.duration = 1.0;
animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
animation.fromValue = [NSValue valueWithCGRect:bounds];
bounds.origin.y += 1000;
animation.toValue = [NSValue valueWithCGRect:bounds];
[scrollview.layer addAnimation:animation forKey:@"bounds"];
scrollview.bounds = bounds;
}
的scrollView
的实际高度是小于总的动画,所以我想重新设置contentOffset
为0当滚动视图达到其高度时,并无缝地继续动画。
当我尝试内
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
if (scrollView.contentOffset.y >= 600)
{
[scrollView setContentOffset:CGPointMake(0, 0)];
}
}
做到这一点的方法,似乎没有动画过程中被调用。当试图在scrollView
上使用Key-Value观察者时,会发生同样的情况,手动滚动时该方法调用得很好,但在coreAnimation
期间调用方法不错。定期检查使用NSTimer
方法也证明是徒劳的。
如何在coreAnimation
期间获得contentOffset
(或scrollview.bounds
),并重置它?
我希望动画scrollView
,以便内容(几个UILabels
)在大于内容大小的动画上无缝滚动。
我认为可能是这种情况。然而,在触摸事件的正常滚动期间(即使正在进行动量滚动),这些值是可访问的吗?什么是完成这种动画的最简单的方法,即。一个垂直滚动数字自动收报机?目前我正在考虑通过非常小的线性值来动画它,并通过缓动函数计算持续时间值,但这似乎不是实现它的最佳方式。 – stefmalawi 2013-04-24 00:43:34
UIScrollView真的不是为此而构建的。你可以看看这里的一些答案:http://stackoverflow.com/questions/5675535/how-to-implement-cyclic-scrolling-on-tableview,但我不认为你会最终以一个伟大的解。 – 2013-04-24 16:39:15