Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I scroll to a position programmatically in UIScrollView

I have a scroll view which scrolls horizontally. I just added images, labels and a webview in it and there are many objects in it. I want to directly scroll to the first object in the scroll view. How do I do this?

like image 558
user1072740 Avatar asked Dec 27 '11 12:12

user1072740


2 Answers

Use the following code:

scrollView.contentOffset = CGPoint(x: 0, y: 0) 
like image 196
Saurabh Passolia Avatar answered Oct 09 '22 09:10

Saurabh Passolia


To animate your scrolling do this:

CGRect frame = CGRectMake(0, 768, 1024, 748); //wherever you want to scroll  [self.scrollView scrollRectToVisible:frame animated:YES]; 
like image 33
inorganik Avatar answered Oct 09 '22 08:10

inorganik