簡體   English   中英

如何在UINavigationControllers中鎖定方向

[英]How to lock orientation in UINavigationControllers

由於在iOS 6中不推薦使用ShouldAutorotateToInterfaceOrientation ,因此無法在我的應用中鎖定方向。 在我的應用程序中,我有UINavigationControllers有多個視圖,一些視圖需要支持縱向和橫向,而其他視圖只需要支持肖像。 我怎么能過來這個問題請給我一些想法。

謝謝

使用此功能僅適用於iOS 6

-(NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskPortrait;
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation

{

    return UIInterfaceOrientationMaskPortrait;

}

您可以通過繼承UINavigationController來鎖定方向。

這是一個很好的鏈接,如何做到這一點。

然后,在子類UIViewController中覆蓋以下方法以實現鎖定(在本例中為縱向鎖定)。

-(BOOL)shouldAutorotate
{
    return NO;
}
-(NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskPortrait;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
    return UIInterfaceOrientationPortrait;
}

在viewDidLoad中添加以下代碼

UIViewController *viewController = [[UIViewController alloc] init];
[self presentModalViewController:viewController animated:NO];
[self dismissModalViewControllerAnimated:NO];

用於鎖定縱向方向

  • 選擇屬性檢查器選項卡。
  • 將方向設置為縱向。

添加功能

 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return ( UIInterfaceOrientationIsPortrait(interfaceOrientation)); 
}

用於鎖定橫向方向

  • 選擇屬性檢查器選項卡。
  • 將方向設置為橫向。

添加功能

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return ( UIInterfaceOrientationIsLandscape(interfaceOrientation) ); 
}

我找到了ShouldAutorotateToInterfaceOrientation的替代品。我想建議你仔細閱讀這些鏈接 -

http://www.roostersoftstudios.com/2012/09/21/ios6-autorotation-changes

謝謝

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM