Search code examples
objective-ciphonescrollpaginationuiscrollview

UIScrollView: How to scroll one page at a time


I have make a scroll view that can scroll horizontally. The problem I am facing is that I want user only scroll one page at a time but at the moment the user and scroll over the scrollview on the emulator and scrolling over two pages.

Does anyone know how to keep the scrollview to scroll only one page at a time? at the moment I have paging enable.


Solution

  • suppose you have to show some images inside an Array.

    [yourScroll setContentSize CGSizeMake( [arrayImages count]*320 , 420)];
    [yourScroll setPagingEnabled : YES];
    int incX = 0 ;
    
    for( int i = 0; i < [arrayImages count]; i++)
    {
      UIImageView *imgView = [[UIImageView alloc]initWithFrame : CGRectMake(0,0,320,420)];
      UIView *myView = [UIView alloc]initWithFrame : CGRectMake (incX,0,320,420);
      imgView.image = [UIImage imageNamed:[NSString stringWithFormat:@"%@",[arrayImages objectAtIndex : i]]];
      [myView addSubView : imgView];  
      [yourScroll addSubView : myView];
       incX+= 320;
    }