屏幕旋转

设置是否允许屏幕旋转

- shouldAutorotate{

    return YES;

}

设置可旋转的方向

- supportedInterfaceOrientations{

    return UIInterfaceOrientationMaskAll;

}

 

 iOS8之前的屏幕旋转的方法,之后已经被弃用,但是现在依然可以使用.

//当将要开始旋转的时候触发

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration{

    //该方法中,一般做暂停音乐,关闭用户交互等操作

    NSLog(@"将要开始旋转了");

}

//旋转完成时触发

- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation{

    //该方法中,一般做重新开启音乐,打开用户交互等操作

    NSLog(@"已经完成屏幕旋转了");

}

//当开始做旋转动画时触发

- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration{

    //可以自定义旋转的动画效果

}

#warning iOS8之后使用这个方法代替

- (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator{

    

}

当屏幕旋转时会触发layoutSubviews方法,可以在此方法中重新布局子视图

//当视图的子视图的位置将要发生变化的时候会调用该方法重新布局视图的子视图.

//当对子视图设置frame时与将子视图放到父视图上时,系统分别调用layoutSubviews方法.

- (void)layoutSubviews{

    //获取手机状态栏的位置,以判断应用程序当前的位置.

    UIInterfaceOrientation location = [UIApplication sharedApplication].statusBarOrientation; //单例

    switch (location) {

        case UIInterfaceOrientationUnknown: {

            NSLog(@"发生未知错误");

            break;

        }

        case UIInterfaceOrientationPortrait:

        case UIInterfaceOrientationPortraitUpsideDown: {

            self.btn.frameCGRectMake(kButtonSpaceLeft, kButtonSpaceTop, kButtonWidth, kButtonHight);

            break;

        }

        case UIInterfaceOrientationLandscapeLeft:

        case UIInterfaceOrientationLandscapeRight: {

//            CGRect frame = self.btn.frame;

            self.btn.frame = CGRectMake(kButtonNewSpaceLeft, kLabelSpaceTop, kButtonWidth, kButtonHight);

            break;

        }

        default: {

            break;

        }

    }

}

转载于:https://www.cnblogs.com/lion-witcher/p/5155654.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值