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