//视图控制器(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