“interfaceOrientation” is deprecated in iOS 8, How to change this method Objective C

后端 未结 5 1236
花落未央
花落未央 2020-12-07 19:39

I have downloaded a simpleCamera view from Cocoa Controls which use this method

- (AVCaptureVideoOrientation)orientationForConnection
{
    AVCaptureVideoOri         


        
5条回答
  •  眼角桃花
    2020-12-07 20:17

    Using -orientation property of UIDevice is not correct (even if it could work in most of cases) and could lead to some bugs, for instance UIDeviceOrientation consider also the orientation of the device if it is face up or down, there is no pair in UIInterfaceOrientation enum for those values.
    Furthermore, if you lock your app in some particular orientation, UIDevice will give you the device orientation without taking that into account.
    On the other side iOS8 has deprecated the interfaceOrientation property on UIViewController class.
    There are 2 options available to detect the interface orientation:

    • Use the status bar orientation
    • Use size classes, on iPhone if they are not overridden they could give you a way to understand the current interface orientation

    What is still missing is a way to understand the direction of a change of interface orientation, that is very important during animations.
    In the session of WWDC 2014 "View controller advancement in iOS8" the speaker provides a solution to that problem too, using the method that replaces -will/DidRotateToInterfaceOrientation.

    Here the proposed solution partially implemented:

    -(void) viewWillTransitionToSize:(CGSize)s withTransitionCoordinator:(UIVCTC)t {
        orientation = [self orientationFromTransform: [t targetTransform]]; 
        oldOrientation = [[UIApplication sharedApplication] statusBarOrientation]; 
        [self myWillRotateToInterfaceOrientation:orientation duration: duration]; 
        [t animateAlongsideTransition:^(id ) {
             [self myWillAnimateRotationToInterfaceOrientation:orientation
                                                      duration:duration];
          }
          completion: ^(id ) {
             [self myDidAnimateFromInterfaceOrientation:oldOrientation];
          }];
    }
    

提交回复
热议问题