用来控制当前视图控制器是否支持旋转
- (BOOL)shouldAutorotate // 自动旋转
{
return YES;
}



设置屏幕旋转的方向,系统默认支持三个方向的旋转,竖直,左右横屏.
UIInterfaceOrientationMaskPortrait 竖直方向 正方向
UIInterfaceOrientationMaskLandscapeLeft 左横屏
UIInterfaceOrientationMaskLandscapeRight 右横屏
UIInterfaceOrientationMaskLandscape 左右 横屏


- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskAll;
}



当屏幕将要旋转时触发(此时屏幕还未旋转)
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
[super willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration];
}


当屏幕旋转时触发.
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{

在该方法中,如果想要在屏幕旋转时添加自己的动画,在该方法中实现.
[super willAnimateRotationToInterfaceOrientation:toInterfaceOrientation duration:duration];
}



当屏幕旋转完成之后触发.
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
{

[super didRotateFromInterfaceOrientation:fromInterfaceOrientation];
旋转之后,继续音乐播放,继续播放视频,打开用户交互.
}


当对视图控制器上的View布局时重新布局时 触发.
- (void)viewWillLayoutSubviews
{

[super viewWillLayoutSubviews];

}




释放掉暂时不使用的内存,供当前程序使用.
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
Dispose of any resources that can be recreated.
当收到内存警告时,移除未在当前屏幕显示的视图.

判断是否可以安全的移除控制器的View
判断当前视图控制器的view是否正在屏幕上显示. self.view.window 是否为nil;

判断当前视图控制器的view是否已经成功加载. isViewLoaded 视图是否加载


if (!self.view.window && [self isViewLoaded])
{
安全移除控制器的view
self.view = nil; 相等于 [_view release]; _view = nil;
}


}



当屏幕每次旋转时都会触发视图的重新布局方法,为该视图上的子视图重新布局.
- (void)layoutSubviews
{
[super layoutSubviews];


对子视图重新布局.
根据屏幕旋转的方向,决定布局的样式.
1.获取屏幕旋转的方向 statusBarOrientation 状态条 高度 20

switch ([UIApplication sharedApplication].statusBarOrientation) {
case UIInterfaceOrientationPortrait:



case UIInterfaceOrientationPortraitUpsideDown:

break;
case UIInterfaceOrientationLandscapeLeft:

break;

case UIInterfaceOrientationLandscapeRight:


break;


default:
break;
}
}