UIScrollview setContentOffset与非线性动画? [英] UIScrollview setContentOffset with non linear animation?

查看:158
本文介绍了UIScrollview setContentOffset与非线性动画?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当您实际滚动到下一页时,我试图重现滚动视图的平滑动画,并启用分页。它似乎是 UIViewAnimationCurveEaseInOut ,但我需要一个下一页按钮并以编程方式触发滚动。

I am trying to reproduce the smooth animation of a scrollview with paging enabled when you actually scroll to the next page. It seems to be UIViewAnimationCurveEaseInOut, but I need to have a "next page" button and trig the scroll programmatically.

这是我的代码:

-(void) scrollToPage:(int)page
{
    UIScrollView *scrollView = contentView;
    CGPoint offset = CGPointMake(scrollView.bounds.size.width * page, scrollView.contentOffset.y);
    [scrollView setContentOffset:offset animated: YES];     
    [self pageControlUpdate];
}

-(void) scrollToNextPage 
{
    [self scrollToPage:(pageControl.currentPage + 1)];
}

我无法重现 UIViewAnimationCurveEaseInOut <的平滑度/ code>,
使用 setContentOffset ,或使用 scrollRectToVisible ...
它带着丑陋的线性动画进入下一页

I cannot manage to reproduce the smoothness of UIViewAnimationCurveEaseInOut, either with setContentOffset, or with scrollRectToVisible... it goes to the next page with an ugly linear animation

我甚至尝试手动设置动画:

I even tried to animate it manually :

[UIView animateWithDuration:.5 delay:0 options:UIViewAnimationCurveEaseInOut animations:^{
    scrollView.contentOffset = offset;
} completion:^(BOOL finished) {    } ];

我哪里错了?

推荐答案

每次制作自己的动画时,都必须将传递给动画:参数:

Every time you make your own animations you have to pass NO as animated: parameter:

- (void)scrollToPage:(int)page
{
    UIScrollView *scrollView = contentView;
    CGPoint offset = CGPointMake(scrollView.bounds.size.width * page, 
                                 scrollView.contentOffset.y);

    [UIView animateWithDuration:.5
                          delay:0
                        options:UIViewAnimationCurveEaseInOut
                     animations:^{
                         [scrollView setContentOffset:offset animated:NO];
                     } completion:nil];

    [self pageControlUpdate];
}

这篇关于UIScrollview setContentOffset与非线性动画?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆