Minor problem with UIScrollView paging

Discussion in 'iOS Programming' started by mathieuhendey, Feb 23, 2012.

  1. macrumors newbie

    Dec 27, 2011

    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.
  2. macrumors 604


    Nov 26, 2007
    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?
  3. macrumors newbie


    Nov 24, 2011
    Rugby, UK
    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.

Share This Page