Automatic paging scrollview

自古美人都是妖i 提交于 2019-12-23 04:21:04

问题


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];
}

I'm using Storyboards and ARC.

Thanks


回答1:


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];

Or you could wrap it in a UIView animation:

[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.




回答2:


You're looking for - (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.

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




回答3:


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]


来源:https://stackoverflow.com/questions/13273435/automatic-paging-scrollview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!