How to scroll to position programmatically in UIScrollView

I have a scroll that scrolls horizontally. I just added images, placemarks and web browsing to it, and it has a lot of objects. I want to directly scroll to the first object in the scroll. How to do it?

+42
ios iphone uiscrollview
Dec 27 '11 at 12:57
source share
4 answers

Use the following code:

scrollView.contentOffset = CGPointMake(0,0); 
+87
Dec 27 '11 at 13:00
source share

To animate your scrolling, follow these steps:

 CGRect frame = CGRectMake(0, 768, 1024, 748); //wherever you want to scroll [self.scrollView scrollRectToVisible:frame animated:YES]; 
+43
Sep 13 '12 at 22:53
source share

The easiest way with animation →

 [scrollView setContentOffset:CGPointMake(0, 0) animated:YES] 
+2
Apr 05 '17 at 10:31 on
source share

Quick version 3 of the answer:

scrollView.contentOffset = CGPoint(x: 0.0, y: 0.0)

0
Mar 01 '17 at 1:14
source share



All Articles