自动分页滚动视图 [英] Automatic paging scrollview

查看:64
本文介绍了自动分页滚动视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个问题.我想在滚动视图中向用户显示一些内容.我想从左到右快速自动滚动滚动视图.我尝试使用 DDAutoscrollview(如果有人知道),但它对我不起作用.是否有人为我提供水平自动滚动 Uiscrollview 的解决方案?我已经为滚动视图设置了一个页面控件,因为它使用分页.任何代码片段都会很好.

I have a question. I want to display the user some content in a scrollview. I want to autoscroll the scrollview fast from left to right. I tried to use DDAutoscrollview (If someone knows), but it doesnt work for me. Do have someone a solution for me to autoscroll a Uiscrollview horizontaly? I've settet up a pagecontrol for the scrollview, because it uses paging. Any code snippets would be nice.

我的代码(只是滚动视图):

My code (Just of the Scrollview):

.h

    @interface Interface1 : UIViewController {

    IBOutlet UIScrollView *scroller;


}

.m

- (void)viewDidLoad
{

    [scroller setScrollEnabled:YES];
    [scroller setContentSize:CGSizeMake(960, 230)];

        [super viewDidLoad];
}

我正在使用故事板和 ARC.

I'm using Storyboards and ARC.

谢谢

推荐答案

您不需要为此使用任何额外的库.UIScrollView 有一个 contentOffset 属性,你可以简单地将动画标志设置为 YES:

You don't need to use any extra libraries for this. UIScrollView has a contentOffset property on which you can simply set the animated flag to YES:

[myScrollView setContentOffset:CGPointMake(320, 0) animated:YES];

或者您可以将其包装在 UIView 动画中:

Or you could wrap it in a UIView animation:

[UIView animateWithDuration:1.5f animations:^{
    [myScrollView setContentOffset:CGPointMake(320, 0) animated:NO];
}];

无论哪种方式,您可能都希望将滚动视图的 contentSize 设置为至少 640 宽,以便您可以实际翻页.

Either way, you'll probably want to set the contentSize of the scroll view to at least 640 wide so you can actually page.

这篇关于自动分页滚动视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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