Reputation: 1377
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
Upvotes: 0
Views: 967
Reputation: 130222
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.
Upvotes: 2
Reputation: 3251
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]
Upvotes: 0
Reputation: 18561
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.
Upvotes: 0