我在我的應用程序中有一個UIViewController,導航條如下圖所示。 UIViewController包含一個4頁的UIPageViewController。導航欄上的每個選項卡代表UIPageViewController中的一個頁面。以編程方式平滑滾動UIPageViewController
我想實現這些UIPageViewController頁面之間平滑滾動,即如果我目前是第一個選項卡上,我點擊最後一個選項卡上的導航欄上的UIPageViewController必須通過一切順利滾動標籤到最後一個。雖然現在這個工作,但我看起來不安,因爲看起來很緊張,所以我不滿意。我正在使用
- setViewControllers:direction:animated:completion:
api在頁面之間滾動。
這是我的代碼看起來像
- (void)navigateToNextPage {
//you have navigated to the destination, return
if(self.destinationPageIndex == self.currentPageIndex)
return;
if(self.destinationPageIndex < 0 || self.destinationPageIndex >= [self.pageViewControllerIdentifiers count])
return;
//determine the scroll direction
UIPageViewControllerNavigationDirection direction = self.destinationPageIndex < self.currentPageIndex ? UIPageViewControllerNavigationDirectionReverse : UIPageViewControllerNavigationDirectionForward;
//get the index of the next page to scroll to
NSInteger nextPageIndex = self.destinationPageIndex < self.currentPageIndex ? self.currentPageIndex-1 : self.currentPageIndex+1;
//get the storyboard identifier of the page to navigate to
NSString *identifier = [self.pageViewControllerIdentifiers objectAtIndex:nextPageIndex];
NSString *storyboardName = @"Sales";
id viewController = [COSCheckoutNavigationViewController instantiateControllerFromStoryboardName:storyboardName storyboardIdentifier:identifier];
NSArray *viewControllers = @[viewController];
__weak typeof (self) weakSelf = self;
[self.pageViewController setViewControllers:viewControllers direction:direction animated:YES completion:^(BOOL finished) {
[weakSelf updateCurrentPageIndex];
//navigate to the next page after small delay
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.05 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[weakSelf navigateToNextPage];
});
}];
}
有沒有一種方法,我可以提高在此代碼爲更好的滾動性能?其他任何技術能幫助我實現我想要的嗎?
任何幫助,將不勝感激!
hello @tbag你可以幫我,我堆放在pageViewController中,當pageviewcontroller滾動到下一頁或前頁時,我想改變自定義tabViews的顏色變化。 –