問題描述
UIPageViewController
中是否可以通過編程方式翻頁?
Is it possible to turn page programmatically in UIPageViewController
?
推薦答案
是的,方法是可以的:
- (void)setViewControllers:(NSArray *)viewControllers
direction:(UIPageViewControllerNavigationDirection)direction
animated:(BOOL)animated
completion:(void (^)(BOOL finished))completion;`
這與在頁面上設置第一個視圖控制器的方法相同.類似的,你可以用它去其他頁面.
That is the same method used for setting up the first view controller on the page. Similar, you can use it to go to other pages.
想知道為什么 viewControllers
是一個數組,而不是單個視圖控制器嗎?
Wonder why viewControllers
is an array, and not a single view controller?
這是因為頁面視圖控制器可能有一個脊椎"(就像在 iBooks 中一樣),一次顯示 2 頁內容.如果您一次顯示 1 頁內容,則只需傳入一個 1 元素數組.
That's because a page view controller could have a "spine" (like in iBooks), displaying 2 pages of content at a time. If you display 1 page of content at a time, then just pass in a 1-element array.
Swift 中的一個例子:
An example in Swift:
pageContainer.setViewControllers([displayThisViewController], direction: .Forward, animated: true, completion: nil)
這篇關于是否可以在 UIPageViewController 中以編程方式翻頁?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!