码迷,mamicode.com
首页 > 其他好文 > 详细

视图控制器 旋转

时间:2014-09-05 03:20:21      阅读:200      评论:0      收藏:0      [点我收藏+]

标签:控制器   左右   return   

//用来控制当前视图控制器是否支持旋转
- (BOOL)shouldAutorotate  // 自动旋转
{
    return YES;
}
//设置屏幕旋转的方向,系统默认支持三个方向的旋转,竖直,左右横屏.
// UIInterfaceOrientationMaskPortrait 竖直方向 正方向
//UIInterfaceOrientationMaskLandscapeLeft 左横屏
//UIInterfaceOrientationMaskLandscapeRight 右横屏
//UIInterfaceOrientationMaskLandscape 左右 横屏
- (NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskAll;
}
//当屏幕将要旋转时触发(此时屏幕还未旋转)
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
    //当屏幕将要旋转时,需要暂停音乐播放,视频播放,关闭用户交互.
    NSLog(@"%s",__FUNCTION__);
    [super willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration];
}


//当屏幕旋转时触发.
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
    //在该方法中,如果想要在屏幕旋转时添加自己的动画,在该方法中实现.
    
        NSLog(@"%s",__FUNCTION__);
    [super willAnimateRotationToInterfaceOrientation:toInterfaceOrientation duration:duration];
}

//当屏幕旋转完成之后触发.
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
{
        NSLog(@"%s",__FUNCTION__);
    [super didRotateFromInterfaceOrientation:fromInterfaceOrientation];
    //旋转之后,继续音乐播放,继续播放视频,打开用户交互.
}


//党对视图控制器上的View布局时重新布局时 触发.
- (void)viewWillLayoutSubviews
{
    
    [super viewWillLayoutSubviews];
   // NSLog(@"QC");
}


- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
    [textField resignFirstResponder];
    return YES;

}
- (void )sel:(UIButton *)btn
{
   // [_tf resignFirstResponder];
    
}



//释放掉暂时不使用的内存,供当前程序使用.
- (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;
    }
  //      NSLog(@"View : %@",self.view.window);
    
}



//当屏幕每次旋转时都会触发视图的重新布局方法,为该视图上的子视图重新布局.
- (void)layoutSubviews
{
    [super layoutSubviews];
   // NSLog(@"QCC");
    
    //对子视图重新布局.
    //根据屏幕旋转的方向,决定布局的样式.
    //1.获取屏幕旋转的方向 statusBarOrientation 状态条 高度 20
    
    switch ([UIApplication sharedApplication].statusBarOrientation) {
        case UIInterfaceOrientationPortrait:
        //    NSLog(@"竖直方向(正)");
          //  _button.frame = CGRectMake(60, 240, 200, 40);
            
        case UIInterfaceOrientationPortraitUpsideDown:
       //     NSLog(@"竖直方向(反)");
            _button.frame = CGRectMake(60, 240, 200, 40);
            break;
        case UIInterfaceOrientationLandscapeLeft:
        //    NSLog(@"左方向");
            //_button.frame = CGRectMake(320, 160, 60, 40);
           
        case UIInterfaceOrientationLandscapeRight:
            
            //设置横屏时视图的显示样式
            _button.frame = CGRectMake(320, 160, 60, 40);
       //     NSLog(@"右方向");
            break;
            
        
        default:
            break;
    }
}

视图控制器 旋转

标签:控制器   左右   return   

原文地址:http://qccccc.blog.51cto.com/6004423/1548924

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!