2

In ios10 ,setStatusBarOrientation is deprecated. some snippet of the old project code can't work fine. So how to solve them? the following code will change the the viewcontroller as we want:

 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];
spartawhy117
  • 511
  • 1
  • 5
  • 22

1 Answers1

2

It is to be believed that -[UIApplication statusBarOrientation] has been deprecated to support the use of UITraitCollection and size classes.

Also from apple docs

@property(readonly, nonatomic) UIInterfaceOrientation statusBarOrientation __TVOS_PROHIBITED;

// Explicit setting of the status bar orientation is more limited in iOS 6.0 and later. @property(readwrite, nonatomic) UIInterfaceOrientation statusBarOrientation NS_DEPRECATED_IOS(2_0, 9_0, "Explicit setting of the status bar orientation is more limited in iOS 6.0 and later") __TVOS_PROHIBITED;

Seems you cannot use the above code for the same purpose.

May be this link helps you Link to orientation

cole
  • 3,147
  • 3
  • 15
  • 28