PDA

View Full Version : Minor problem with UIScrollView paging




mathieuhendey
Feb 23, 2012, 12:23 PM
Hi

I'm having a minor problem with my paging UIScrollView. It works correctly, but there is some odd behaviour. Basically, the scrollView contains 7 UIImages with gestureRecognizers. Now, the selectors all fire when I tap the Images, but the scrollView also resets itself so it's back on the first page any time I tap anywhere. I am making the scrollView programatically. Here is how I'm doing that:


scrollView = [[UIScrollView alloc] init];
scrollView.frame = CGRectMake(0,0,316,50);
scrollView.contentSize = CGSizeMake(460, 50);
scrollView.pagingEnabled = YES;

Any help would be awesome.



ArtOfWarfare
Feb 23, 2012, 02:45 PM
Your problem occurs when the user taps on the images, not at setup, so wouldn't seeing the code that's executed when a tap is detected be more useful?

OverByThere
Feb 26, 2012, 06:07 AM
As ArtOfWarfare has stated, we do need to know the code you use to move between images.

Here is some code I use in a current app to move to another page:
CGRect nextFrame = myScrollView.frame;
nextFrame.origin.x = nextFrame.size.width*currentPage;
[myScrollView scrollRectToVisible:nextFrame animated:YES];

Using the above code, currentPage is a integer containing the page I'm on, so always will return 1,2,3 etc, then multiplying by the frame's width, will tell the scrollview to display that CGRect area.