UIscrollView动画不流畅

UIscrollView animation not smoothly

代码:

-(void)scrollViewWillBeginDecelerating:(UIScrollView *)scrollView{

    int diff = end-start;

    if (diff>0)
    {
        k = k + 95;
    }
    else {

        k = k - 95;
    }

     [scrollView setContentOffset:CGPointMake(k, 0) animated:YES];
}

- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
{
        start = scrollView.contentOffset.x;
}

- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate
{
        end = scrollView.contentOffset.x;

}

我有一个带有 3 个标签的滚动视图。左侧 90 像素宽度,中心 90 像素宽度和右侧 90 像素 width.Each 标签有 5 像素 gap.when 滚动视图向左或向右滚动 我对齐下一个或上一个标签中心 screen.Logic 正在工作 fine.but 动画不流畅,启动后还有停顿 animation.How 我能解决这个问题吗?我如何加快动画速度?任何帮助将不胜感激。

我认为更好的方法是只使用 UIScrollView 的

pagingEnabled = YES;

并且您不需要上述委托方法。确保您已设置 contentSize。

您可以通过以下方式调整滚动速度,通过调整持续时间值。 </p> <pre>[UIView animateWithDuration:0.5 animations:^{ _scrolview.contentOffset = CGPointMake(k, 0); }];