您好,登錄后才能下訂單哦!
- (void)viewDidLoad
{
[super viewDidLoad];
[self createContentPages];// 初始化所有數據
// 設置UIPageViewController的配置項
NSDictionary *options =[NSDictionary dictionaryWithObject:[NSNumber numberWithInteger:UIPageViewControllerSpineLocationMin]
forKey: UIPageViewControllerOptionSpineLocationKey];
// 實例化UIPageViewController對象,根據給定的屬性
self.pageController = [[UIPageViewController alloc] initWithTransitionStyle:UIPageViewControllerTransitionStylePageCurl
navigationOrientation:UIPageViewControllerNavigationOrientationHorizontal
options: options];
[[_pageController view] setFrame:[[self view] bounds]];
}
1.UIPageViewControllerDataSource協議
該協議主要有兩個方法:
- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerBeforeViewController:(UIViewController *)viewController;
- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerAfterViewController:(UIViewController *)viewController;
分別用來提供UIPageViewController對象的數據源,即UIPageViewController對象通過該方法來調度顯示的內容。
_pageController.dataSource = self;
2.初始化時,顯示適當內容
MoreViewController *initialViewController =[self viewControllerAtIndex:0];// 得到第一頁
NSArray *viewControllers =[NSArray arrayWithObject:initialViewController];
[_pageController setViewControllers:viewControllers
direction:UIPageViewControllerNavigationDirectionForward
animated:NO
completion:nil];
// 在頁面上,顯示UIPageViewController對象的View
[self addChildViewController:_pageController];
[[self view] addSubview:[_pageController view]];
3.準備好數據源
[self createContentPages];// 初始化所有數據
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。