Automatic paging scrollview

2019-06-10 17:17发布

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

3条回答
该账号已被封号
2楼-- · 2019-06-10 17:47

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]
查看更多
Luminary・发光体
3楼-- · 2019-06-10 17:56

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.

查看更多
对你真心纯属浪费
4楼-- · 2019-06-10 17:59

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

查看更多
登录 后发表回答