2017-07-14 24 views
1

在ios10中,不推薦使用setStatusBarOrientation。舊項目代碼的一些片段無法正常工作。那麼如何解決它們呢?下面的代碼將改變的視圖 - 控制,因爲我們希望:setStatusBarOrientation不推薦使用,如何在ios10中更改設備方向

float angle; 
CGRect rect; 
// UIInterfaceOrientation orientation; 
    float fWidth = _viewController.view.bounds.size.width; 
    float fHeight = _viewController.view.bounds.size.height; 
    float fMaxValue = (fWidth > fHeight) ? fWidth : fHeight; 
    float fMinValue = (fWidth > fHeight) ? fHeight : fWidth; 

    if ((eScreenOrientation)ore == eScreenOrientation::Landscape) { 
     if ([[UIDevice currentDevice] orientation] == UIDeviceOrientationLandscapeLeft) { 
//   orientation = UIInterfaceOrientationLandscapeRight; 
      angle = M_PI_2; 
     } else { 
//   orientation = UIInterfaceOrientationLandscapeLeft; 
      angle = -M_PI_2; 
     } 
     rect = CGRectMake(0, 0, fMaxValue, fMinValue); 
    } else { 
//  orientation = UIInterfaceOrientationPortrait; 
     angle = 0; 
     rect = CGRectMake(0, 0, fMinValue, fMaxValue); 
    } 

// [[UIApplication sharedApplication] setStatusBarOrientation: orientation]; 
    _viewController.view.transform = CGAffineTransformMakeRotation(angle); 
    _viewController.view.bounds = rect; 
    [_viewController resetViewSize]; 

回答

1

應當相信 - [UIApplication的statusBarOrientation]已被棄用,以支持使用UITraitCollection和大小的類。

從蘋果文檔

另外

@property(只讀,非原子)UIInterfaceOrientation statusBarOrientation __TVOS_PROHIBITED;

//在iOS 6.0及更高版本中,狀態欄方向的顯式設置更受限制。 @property(readwrite,nonatomic)UIInterfaceOrientation statusBarOrientation NS_DEPRECATED_IOS(2_0,9_0, 「在iOS 6.0及更高版本中,狀態欄方向的顯式設置更受限制」)__TVOS_PROHIBITED;

似乎你不能將上述代碼用於同一目的。

可能是此鏈接幫助你Link to orientation