Reputation: 8405
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.
Upvotes: 2
Views: 3619
Reputation: 1424
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;
}
Upvotes: 4
Reputation: 4092
You must be doing something wrong. If you have paging enabled, it will automatically align to pages(where page size is size of scrollview frame). Maybe you are paging programatically somewhere(which is not needed if pagingEnabled is true).
Can't tell more without the code
Upvotes: 0
Reputation: 7643
For example:
- (IBAction)changePage:(id)sender
{
NSInteger _currentPage = self.pageControl.currentPage;
CGPoint offset = CGPointMake(_currentPage * self.scrollView.frame.size.width, 0);
[self.scrollView setContentOffset:offset animated:YES];
pageControlUsed = YES;
}
Upvotes: 1