Minor problem with UIScrollView paging

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

  1. macrumors newbie

    Joined:
    Dec 27, 2011
    #1
    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:

    Code:
        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

    ArtOfWarfare

    Joined:
    Nov 26, 2007
    #2
    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

    OverByThere

    Joined:
    Nov 24, 2011
    Location:
    Rugby, UK
    #3
    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:
    Code:
    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