ios 旋转屏幕试图切换_iOS中的屏幕的旋转(UIViewController)横屏竖屏

//视图控制器(UIViewController):它不是视图,用来管理视图,所以屏幕上看不到,但是自身携带一个视图(根视图)

#import "RootViewController.h"#import"LoginView.h"

//视图控制器的延展

@interface RootViewController ()

@end//视图控制器的实现部分

@implementation RootViewController//用来加载视图控制器的根视图,此方法源于父类

- (void)loadView

{

LoginView*logview =[[LoginView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];//指定刚才创建的 自定义视图 对象为当前视图控制器的根视图

self.view =logview;

[logview release];

}//该方法是在loadView执行完之后立即执行的方法//当访问视图控制器的View为空,一但发现View为空,立即调用loadView来加载根视图//如果要自定义视图控制器的根视图,只需要重写loadView方法,在loadView方法中完成创建,并指定当前试图控制器的根视图即可

- (void)viewDidLoad {

[super viewDidLoad];//Do any additional setup after loading the view.

NSLog(@"%s,%d",__FUNCTION__,__LINE__);//self.view.backgroundColor = [UIColor redColor];

}#pragma mark -- 检测和处理屏幕的旋转

//1.设置屏幕支持的旋转方向

-(NSUInteger)supportedInterfaceOrientations{returnUIInterfaceOrientationMaskAll;

}//开始旋转时会触发的方法//经常用来暂停播放器播放,暂停视屏播放,以及关闭用户交互

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

[super willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration];

}//当旋转结束是时触发//继续音乐,视频播放,以及打开的用户交互

- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation{

[super didRotateFromInterfaceOrientation:fromInterfaceOrientation];

}//当将要开始旋转做动画时触发,经常用来在旋转时添加自定义动画

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

[super willAnimateRotationToInterfaceOrientation:toInterfaceOrientation duration:duration];

}#pragma ---视图控制器控制布局视图的方法

//当视图旋转时,视图控制器触发的方法,用于重新布局视图控制器根据视图上得子视图

- (void)viewWillLayoutSubviews{

[super viewWillLayoutSubviews];

}//当视图控制器收到内存警告时触发//释放之前未使用的空间,以及可以重建的对象.

- (void)didReceiveMemoryWarning {

[super didReceiveMemoryWarning];//Dispose of any resources that can be recreated.//1.视图控制器的根视图是够已经成功加载//2.当前根视图是否正在显示//[self isViewLoaded]判断视图是否成功加载//self.view.window,判读视图是否在当前界面//内存加载成功,且不在当前界面

if ([self isViewLoaded] && !self.view.window) {

[self.view release];

}

}

@end

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值