ScrollViewDidScroll中的动画

时间:2013-03-14 18:52:03

标签: ios uiscrollview

我通过修改PullToRefresh lib在scrollViewDidScroll中解除了UIView动画。我想要的是当用户开始拉动并在拉动刷新标题视图离开屏幕时终止它时触发动画。但是,动画仅在用户释放拉动时起作用;在用户继续拉动期间,动画不起作用...非常感谢您提前帮助! :)

- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{   
    if (scrollView.isDragging) {
        if (refreshHeaderView.state == EGOOPullRefreshPulling && scrollView.contentOffset.y > -65.0f && scrollView.contentOffset.y < 0.0f && !_reloading) {
            [refreshHeaderView setState:EGOOPullRefreshNormal];
            if (timer) {
                [timer invalidate];
                timer = nil;
            }
        } else if (refreshHeaderView.state == EGOOPullRefreshNormal && scrollView.contentOffset.y < -65.0f && !_reloading) {
            [refreshHeaderView setState:EGOOPullRefreshPulling];
            if (!timer) {
                timer = [NSTimer scheduledTimerWithTimeInterval:0.5 target:self selector:@selector(startMyAnimation) userInfo: nil repeats: YES];
            }
        }
    }
}

1 个答案:

答案 0 :(得分:3)

通常,当用户在滚动视图中拖动时,计时器不会触发。

尝试按如下方式安排计时器:

timer = [NSTimer timerWithTimeInterval:0.5 target:self selector:@selector(startMyAnimation) userInfo: nil repeats: YES];
[[NSRunLoop currentRunLoop] addTimer:timer forMode:NSRunLoopCommonModes];