0

我有一个UIScrollView用 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)];
    }
}

在动画期间似乎没有调用该方法。当尝试scrollViewcoreAnimation. 使用NSTimer定期检查的方法也被证明是徒劳的。

如何在 a 期间获取contentOffset(or scrollview.bounds)coreAnimation并重置它?
我希望制作动画,scrollView以便内容(几个UILabels)在大于内容大小的动画上无缝滚动。

4

1 回答 1

2

UIScrollViews 实际上并没有在动画期间改变它们的偏移量。如果您想“重置”偏移量,我建议您弄清楚如何在正确的时间结束动画并在之后设置边界。

你也可以使用 UIScrollView 的setContentOffset:animated:方法。您将无法控制动画,但您会在动画滚动和完成时收到通知。

于 2013-04-23T23:17:22.233 回答