iOS屏幕旋转

    -(BOOL)shouldAutorotate{  
        //用来设置当前视图控制器是否支持旋转  
        return YES;  
    }  
    //设置屏幕旋转方向 系统默认支持三个方向的旋转 竖直 左横屏 右横屏  
    -(NSUInteger)supportedInterfaceOrientations{  
    //    UIInterfaceOrientationMaskPortrait 竖直方向  
    //    UIInterfaceOrientationMaskLandscapeLeft 左横屏  
    //    UIInterfaceOrientationMaskLandscapeRight 右横屏  
    //    UIInterfaceOrientationMaskLandscape 左横屏 右横屏  
    //    UIInterfaceOrientationMaskAll  上下左右都有  
        return UIInterfaceOrientationMaskAll;  
    }  
      
    -(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration{  
        //当屏幕将要旋转时 触发 (此时屏幕还未旋转)  
        //当屏幕旋转时 需要暂停音乐播放,视频播放,关闭用户交互  
        [super willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration];  
    }  
    -(void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration{  
        //屏幕旋转时  
        //如果想要在屏幕旋转时添加自定义的动画  
        [super willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration];  
    }  
      
    -(void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation{  
        //当屏幕旋转完成之后触发  
        //继续音乐,视频 播放  打开用户交互  
        [super didRotateFromInterfaceOrientation:fromInterfaceOrientation];  
    }  

[objc] view plaincopyprint?

    <pre name="code" class="objc">//系统UIView 的方法  
    -(void)layoutSubviews{  
        //当屏幕每次旋转时都会触发视图重新布局方法 为视图上的子视图重新布局  
        [super layoutSubviews];  
        //对子视图重新布局.根据屏幕旋转的方向 决定布局的样式  
    //    1 获取屏幕旋转方向  
        switch ([UIApplication sharedApplication].statusBarOrientation) {  
            case UIInterfaceOrientationPortrait:  
                NSLog(@"竖直方向(正)");  
                case UIInterfaceOrientationPortraitUpsideDown:  
                NSLog(@"竖直方向(倒)");  
                _butten.frame = CGRectMake(50, 240, 220, 40);  
                break;  
                case UIInterfaceOrientationLandscapeLeft:  
                case UIInterfaceOrientationLandscapeRight:  
                //设置横屏时视图的显示样式  
                _butten.frame = CGRectMake(320, 150, 60, 30);  
                break;  
                  
            default:  
                break;  
        }  
    } 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值