简体   繁体   English

自动分页滚动视图

[英]Automatic paging scrollview

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. 我试图使用DDAutoscrollview(如果有人知道),但它对我不起作用。 Do have someone a solution for me to autoscroll a Uiscrollview horizontaly? 有人帮我自动滚动Uiscrollview吗? I've settet up a pagecontrol for the scrollview, because it uses paging. 我为scrollview设置了一个pagecontrol,因为它使用了分页。 Any code snippets would be nice. 任何代码片段都会很好。

My code (Just of the Scrollview): 我的代码(Just of the Scrollview):

.h 。H

    @interface Interface1 : UIViewController {

    IBOutlet UIScrollView *scroller;


}

.m .M

- (void)viewDidLoad
{

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

        [super viewDidLoad];
}

I'm using Storyboards and ARC. 我正在使用Storyboards和ARC。

Thanks 谢谢

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: UIScrollView有一个contentOffset属性,您可以在其上简单地将动画标志设置为YES:

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

Or you could wrap it in a UIView animation: 或者你可以将它包装在UIView动画中:

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

Either way, you'll probably want to set the contentSize of the scroll view to at least 640 wide so you can actually page. 无论哪种方式,您可能希望将滚动视图的contentSize设置为至少640宽,以便您可以实际进行分页。

You're looking for - (void)scrollRectToVisible:(CGRect)rect animated:(BOOL)animated . 你正在寻找- (void)scrollRectToVisible:(CGRect)rect animated:(BOOL)animated It will allow you to give it a rect inside your contentSize and it will scroll to it. 它允许你在contentSize中给它一个rect,它会滚动到它。

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

I don't know how fast exactly but have you tried this method? 我不知道究竟有多快,但你尝试过这种方法吗?

- (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