1. 程式人生 > >iOS 9 橫豎屏 切換 適配

iOS 9 橫豎屏 切換 適配

- (void)viewDidLoad {

    [superviewDidLoad];

// Do any additional setup after loading the view.

    [selfcreateBackBtn];

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(screenRotate:animation:) name:@"UIWindowWillRotateNotification" object:nil];

}

-(void)dealloc{

    [[NSNotificationCenterdefaultCenter] removeObserver:selfname:@"UIWindowWillRotateNotification"object:nil];

}

- (void)screenRotate:(NSNotification *)noti animation:(BOOL)animation

{

UIInterfaceOrientation orientation = [[noti.userInfoobjectForKey:@"UIWindowNewOrientationUserInfoKey"]

integerValue];

    if (!noti) {

        return;

    }

    animation = YES;

NSTimeInterval i = [UIApplicationsharedApplication].statusBarOrientationAnimationDuration;

    NSTimeInterval time = 0.3 + i;

    if (!animation) {

        time = 0.0;

    }

    switch (orientation)

    {

caseUIInterfaceOrientationPortrait:

        {

if ([_ORIENTATIONisEqualToString:@"UIInterfaceOrientationPortrait"]) {

                return;

            }

DSLog(@"===========HOME===============");

_ORIENTATION = @"UIInterfaceOrientationPortrait";

        }

            break;

caseUIInterfaceOrientationPortraitUpsideDown:

        {

if ([_ORIENTATIONisEqualToString:@"UIInterfaceOrientationPortraitUpsideDown"]) {

                return;

            }

DSLog(@"==========HOME================");

_ORIENTATION = @"UIInterfaceOrientationPortraitUpsideDown";

        }

            break;

caseUIInterfaceOrientationLandscapeRight:

        {

if ([_ORIENTATIONisEqualToString:@"UIInterfaceOrientationLandscapeRight"]) {

                return;

            }

DSLog(@"=========HOME====右邊=============");

_ORIENTATION = @"UIInterfaceOrientationLandscapeRight";

// 這裡是給相應的view對應旋轉

//            [UIView animateWithDuration:time animations:^{

//                _userVc.view.transform = CGAffineTransformMakeRotation(M_PI_2);

//            } completion:nil];

        }

            break;

caseUIInterfaceOrientationLandscapeLeft:

        {

if ([_ORIENTATIONisEqualToString:@"UIInterfaceOrientationLandscapeLeft"]) {

                return;

            }

DSLog(@"==========HOME===左邊=============");

_ORIENTATION = @"UIInterfaceOrientationLandscapeLeft";

// 這裡是給相應的的view對應旋轉

//            [UIView animateWithDuration:time animations:^{

//                _userVc.view.transform = CGAffineTransformMakeRotation(-M_PI_2);

//            } completion:nil];

        }

            break;

        default:

            break;

    }

}