I have a horizontal UIScrollview setting (this means that it is not the one that scrolls up and down, but only scrolls left and right) and when I start the application, I want this scroll to look at itself from the left, and then the right one - demonstrating "its ability scrolling - and finally stops, allowing the user to then grab and control the scroll manually with his finger. Everything works - except for this demo of scrolling left and right.
I do not use Interface Builder for any of this, I do everything with code:
//(this is in viewDidLoad:) // Create the scrollView: UIScrollView *photosScroll = [[UIScrollView alloc] initWithFrame: CGRectMake(0, 0, 320, 200)]; [photosScroll setContentSize: CGSizeMake(1240, 200)]; // Add it as a subview to the mainView [mainView addSubview:photosScroll]; // Set the photoScroll delegate: photosScroll.delegate = self; // Create a frame to which to scroll: CGRect frame = CGRectMake(10, 10, 80, 150); // Scroll to that frame: [photosScroll scrollRectToVisible: frame animated:YES];
So, scrollView loads successfully, and I can scroll it left and right with my finger, but it doesn’t do this “auto scroll” as I hoped.
- I tried calling scrollRectToVisible before and after adding scrollView as a subtitle - it didn't work.
- Think this should be happening in loadView and not in viewDidLoad? But if so, how?
Any ideas?
source share