繁体   English   中英

自动分页滚动视图

[英]Automatic paging scrollview

我有个问题。 我想在滚动视图中向用户显示一些内容。 我想从左到右快速自动滚动滚动视图。 我试图使用DDAutoscrollview(如果有人知道),但它对我不起作用。 有人帮我自动滚动Uiscrollview吗? 我为scrollview设置了一个pagecontrol,因为它使用了分页。 任何代码片段都会很好。

我的代码(Just of the Scrollview):

。H

    @interface Interface1 : UIViewController {

    IBOutlet UIScrollView *scroller;


}

.M

- (void)viewDidLoad
{

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

        [super viewDidLoad];
}

我正在使用Storyboards和ARC。

谢谢

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

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

或者你可以将它包装在UIView动画中:

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

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

你正在寻找- (void)scrollRectToVisible:(CGRect)rect animated:(BOOL)animated 它允许你在contentSize中给它一个rect,它会滚动到它。

http://developer.apple.com/library/ios/#documentation/uikit/reference/UIScrollView_Class/Reference/UIScrollView.html

我不知道究竟有多快,但你尝试过这种方法吗?

- (void)setContentOffset:(CGPoint)contentOffset animated:(BOOL)animated
// In your case, e.g.:
[scroller setContentOffset:CGPointMake(640, 0) animated:YES]

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM