2015-10-19 125 views
2

我目前正在開發基於Page View ControlleriOS項目。一切工作正常,但是,我想阻止用戶超出頁面的限制。如何防止PageViewController溢出?

在示例中,當PageViewController定位在第一頁,如果用戶試圖去前一頁(甚至以爲沒有之一)通過拖動Page View到左邊,Root View Controller出現,直到拖累正如你在下面的截圖中看到的那樣。

enter image description here

有什麼辦法來阻止這個手勢在第一和Page View Controller的最後一頁?

+1

http://stackoverflow.com/questions/22795883/disable-bounce-effect-in-uipageviewcontroller – abhi1992

+1

http://stackoverflow.com/questions/21798218/disable-uipageviewcontroller-bounce – abhi1992

+0

看看這些答案 – abhi1992

回答

2

使用PageviewController委託方法

- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerAfterViewController:(UIViewController *)viewController { 

if (indexTest < NUM_OF_PAGES) { 
    switch (indexTest) { 

     case 0:{ 
      NSLog(@"Page AFTER is Page: %@", [NSString stringWithFormat:@"%@",[viewControllers objectAtIndex:1] ]); 
      indexTest++; 
      return [viewControllers objectAtIndex:1]; 
      break; 
     } 
     case 1:{ 
      NSLog(@"Page AFTER is Page: %@", [NSString stringWithFormat:@"%@",[viewControllers objectAtIndex:2] ]); 
      indexTest++; 
      return [viewControllers objectAtIndex:2]; 
      break; 
     } 
     case 2:{ 
      NSLog(@"No pages AFTER this current page %d", indexTest); 
      break; 
     } 
     default:{ 
      NSLog(@"PROBLEM in viewAFTER, indexTest = %d!!!!", indexTest); 
      break; 
     } 
    } 

} 
return nil; 

}

做這樣的事情,與indexTest是int變量這增加了頁數爲每刷一下。

NUM_OF_PAGES is the total pages available for page controlling.