iOS开发 -- 屏幕旋转

来源:互联网 发布:信欣美妆淘宝店假货 编辑:程序博客网 时间:2024/05/22 15:56

//设置 当前视图控制器 支持旋转的方向

-(BOOL)shouldAutorotate{    return YES;}

//设置当前视图控制器 支持旋转的方向

-(NSUInteger)supportedInterfaceOrientations{    return UIInterfaceOrientationMaskAll;}

代码设置 屏幕旋转并且控制View上视图在横屏和竖屏状态居中

重写layoutSubviews方法

-(void)layoutSubviews{   [super layoutSubviews];    //获取应用程序的对象    UIApplication *app= [UIApplication sharedApplication];   //  //  if (app.statusBarOrientation == UIInterfaceOrientationMaskAll) {    //通过方向进行横屏 竖屏的判断      if (app.statusBarOrientation == UIInterfaceOrientationPortraitUpsideDown || app.statusBarOrientation == UIInterfaceOrientationPortrait) {          NSLog(@"竖屏");          //竖屏布局          self.user.frame = CGRectMake(20, 100,335, 40);          self.passWord.frame = CGRectMake(20, 180, 335, 40);          _loginBt.frame = CGRectMake(40, 300, 60, 40);          _findPasswordBt.frame = CGRectMake(130, 300, 100, 40);          _registBt.frame = CGRectMake(260, 300, 60, 40);    }else if (app.statusBarOrientation == UIInterfaceOrientationLandscapeLeft ||app.statusBarOrientation == UIInterfaceOrientationLandscapeRight)    {//横屏布局        self.user.frame = CGRectMake(100, 100, 467, 40);        self.passWord.frame = CGRectMake(100, 160, 467,40);        self.loginBt.frame = CGRectMake(50, 220, 367/3, 40);        self.findPasswordBt.frame = CGRectMake(50+367/3+50, 220, 367/3, 40);        self.registBt.frame = CGRectMake(50+(367/3+50)*2, 220, 367/3, 40);        NSLog(@"横屏");    }}

iOS8已经被弃用的屏幕旋转的方法 但是这些方法现在也可以用

//此方法iOS8已经被弃用 – 屏幕将要旋转 触发 之前一般用来进行视频,音-(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration{
NSLog(@”屏幕要旋转”);
}

iOS8已经被弃用 – 旋转动画将要开始时候 触发 之前一般进行过

-(void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
NSLog(@”将要开始旋转动画”);
}

iOS8已经被弃用 – 旋转结束时候 触发 之前一般进行暂停音频 视频的重新播放.

-(void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation{    NSLog(@"将要开始旋转");}
0 0
原创粉丝点击