亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

是否可以在UIPageViewController中以編程方式翻頁?

是否可以在UIPageViewController中以編程方式翻頁?

一只名叫tom的貓 2019-08-30 16:50:07
是否可以以編程方式翻頁UIPageViewController?
查看完整描述

3 回答

?
HUWWW

TA貢獻1874條經驗 獲得超12個贊

是的,可以使用以下方法:


- (void)setViewControllers:(NSArray *)viewControllers 

                 direction:(UIPageViewControllerNavigationDirection)direction 

                  animated:(BOOL)animated 

                completion:(void (^)(BOOL finished))completion;`

這與在頁面上設置第一個視圖控制器的方法相同。類似,您可以使用它來轉到其他頁面。


不知道為什么viewControllers是數組,而不是單個視圖控制器?


那是因為頁面視圖控制器可以有一個“書脊”(就像在iBooks中一樣),一次顯示2頁內容。如果一次顯示1頁內容,則只傳入1元素數組。


Swift中的一個例子:


pageContainer.setViewControllers([displayThisViewController], direction: .Forward, animated: true, completion: nil)



查看完整回答
反對 回復 2019-08-30
?
慕萊塢森

TA貢獻1810條經驗 獲得超4個贊

這是單個分頁視圖的另一個代碼示例。這里省略了viewControllerAtIndex的實現,它應該返回給定索引的正確視圖控制器。


- (void)changePage:(UIPageViewControllerNavigationDirection)direction {

    NSUInteger pageIndex = ((FooViewController *) [_pageViewController.viewControllers objectAtIndex:0]).pageIndex;


    if (direction == UIPageViewControllerNavigationDirectionForward) {

        pageIndex++;

    }

    else {

        pageIndex--;

    }


    FooViewController *viewController = [self viewControllerAtIndex:pageIndex];


    if (viewController == nil) {

        return;

    }


    [_pageViewController setViewControllers:@[viewController]

                                  direction:direction

                                   animated:YES

                                 completion:nil];

}

可以通過調用更改頁面


[self changePage:UIPageViewControllerNavigationDirectionReverse];

[self changePage:UIPageViewControllerNavigationDirectionForward];


查看完整回答
反對 回復 2019-08-30
  • 3 回答
  • 0 關注
  • 658 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號