2016-02-22 47 views
1

我從UIPageViewContoller類繼承了3個視圖控制器。他們兩個應該只有肖像方向和一個 - 所有的方向。我添加了這樣一段代碼:UIPageViewController:如何處理視圖控制器的不同方向?

override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask { 
    return self.currentStackVC.supportedInterfaceOrientations() 
} 

override func shouldAutorotate() -> Bool { 
    return self.currentStackVC.shouldAutorotate() 
} 

override func preferredInterfaceOrientationForPresentation() -> UIInterfaceOrientation { 
    return self.currentStackVC.preferredInterfaceOrientationForPresentation() 
} 

override func viewWillTransitionToSize(size: CGSize, withTransitionCoordinator coordinator: UIViewControllerTransitionCoordinator) { 
    super.viewWillTransitionToSize(size, withTransitionCoordinator: coordinator) 

} 

其中currentStackVC是當前可見視圖控制器。 我也有我的視圖控制器這樣的代碼有一點不同的實現:

前兩個viewcontrollers(未來 - VC):

override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask { 
    return UIInterfaceOrientationMask.Portrait 
} 

override func shouldAutorotate() -> Bool { 
    return false 
} 
override func preferredInterfaceOrientationForPresentation() -> UIInterfaceOrientation { 
    return UIInterfaceOrientation.Portrait 
} 

末:

override func shouldAutorotate() -> Bool { 
    return true 
} 

override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask { 
    return UIInterfaceOrientationMask.All 
} 

override func preferredInterfaceOrientationForPresentation() -> UIInterfaceOrientation { 
    return UIInterfaceOrientation.Portrait 
} 

當我位於第三視圖控制器 - 我旋轉我的設備並應用新的方向。但不幸的是,它也適用於其他風險投資公司。系統在第一個和第二個VC中不要求shouldAutorotate()。 (正如我想的那樣,因爲每次只詢問當前的第三VC)。我去第二個VC(使用滑動),並且它也是橫向的。所以,我的問題是 - 如何處理Page VC中不同屏幕的不同方向?

在此先感謝

+0

你設法解決這個問題? – Nil

+0

不,我沒有。 – frankWhite

回答

1

你應該使用UIPageViewController

- (UIInterfaceOrientationMask)pageViewControllerSupportedInterfaceOrientations:(UIPageViewController *)pageViewController NS_AVAILABLE_IOS(7_0) __TVOS_PROHIBITED; 

的委託方法,例如把這個代碼放到UIPageViewController的委託

- (UIInterfaceOrientationMask)pageViewControllerSupportedInterfaceOrientations:(UIPageViewController *)pageViewController { 
    return [[pageViewController.viewControllers lastObject] supportedInterfaceOrientations]; 
} 

,並覆蓋在孩子的VC的方法。

VC1

- (UIInterfaceOrientationMask)supportedInterfaceOrientations { 
    return UIInterfaceOrientationMaskAllButUpsideDown; 
} 

VC2

- (UIInterfaceOrientationMask)supportedInterfaceOrientations { 
    return UIInterfaceOrientationMaskPortrait; 
} 
+0

對不起Objective-C。我認爲它很容易轉換成swift –

+0

沒關係,謝謝,我會嘗試 – frankWhite

相關問題