0
我有一個頁面控件和一個scrollView在我的一個視圖中實現。目前,我有2頁,滾動視圖的內容大小設置爲496(每頁248)的寬度。一切正常,因爲它更新和滾動正確,但是,我注意到,即使沒有頁面左側或右側,我仍然可以繼續滾動。iOS頁面控制滾動鎖定
如果我在第一頁上,或者如果我在最後一頁上禁用滾動,有沒有辦法禁用向左滾動?請看下面的代碼片段,看看我在做什麼。
// Initialize the scroll view
scrollView.pagingEnabled = YES;
scrollView.contentSize = CGSizeMake(scrollView.frame.size.width * 2, scrollView.frame.size.height);
scrollView.showsHorizontalScrollIndicator = NO;
scrollView.showsVerticalScrollIndicator = NO;
scrollView.scrollsToTop = NO;
scrollView.delegate = self;
// Functions called for the page control/scrollview
- (void)loadScrollViewWithPage:(int)page window:(UIView *)pageView
{
if(page < 0 || page >= pageControl.numberOfPages)
{
return;
}
// Add our view
CGRect frame = scrollView.frame;
frame.origin.x = frame.size.width * page;
frame.origin.y = 0;
[pageView setFrame:frame];
[scrollView addSubview:pageView];
}
- (void)scrollViewDidScroll:(UIScrollView *)sender
{
// Update our page when we have more than 50% of the adjacent page available
CGFloat pageWidth = scrollView.frame.size.width;
int page = floor((scrollView.contentOffset.x - pageWidth/2)/pageWidth) + 1;
if(page < 0 || page >= pageControl.numberOfPages)
{
return;
}
pageControl.currentPage = page;
[pageControl setNeedsDisplay];
}