iOS屏幕旋轉

    -(BOOL)shouldAutorotate{  
        //用來設置當前視圖控制器是否支持旋轉  
        return YES;  
    }  
    //設置屏幕旋轉方向 系統默認支持三個方向的旋轉 豎直 左橫屏 右橫屏  
    -(NSUInteger)supportedInterfaceOrientations{  
    //    UIInterfaceOrientationMaskPortrait 豎直方向  
    //    UIInterfaceOrientationMaskLandscapeLeft 左橫屏  
    //    UIInterfaceOrientationMaskLandscapeRight 右橫屏  
    //    UIInterfaceOrientationMaskLandscape 左橫屏 右橫屏  
    //    UIInterfaceOrientationMaskAll  上下左右都有  
        return UIInterfaceOrientationMaskAll;  
    }  
      
    -(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration{  
        //當屏幕將要旋轉時 觸發 (此時屏幕還未旋轉)  
        //當屏幕旋轉時 需要暫停音樂播放,視頻播放,關閉用戶交互  
        [super willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration];  
    }  
    -(void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration{  
        //屏幕旋轉時  
        //如果想要在屏幕旋轉時添加自定義的動畫  
        [super willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration];  
    }  
      
    -(void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation{  
        //當屏幕旋轉完成之後觸發  
        //繼續音樂,視頻 播放  打開用戶交互  
        [super didRotateFromInterfaceOrientation:fromInterfaceOrientation];  
    }  

[objc] view plaincopyprint?

    <pre name="code" class="objc">//系統UIView 的方法  
    -(void)layoutSubviews{  
        //當屏幕每次旋轉時都會觸發視圖重新佈局方法 爲視圖上的子視圖重新佈局  
        [super layoutSubviews];  
        //對子視圖重新佈局.根據屏幕旋轉的方向 決定佈局的樣式  
    //    1 獲取屏幕旋轉方向  
        switch ([UIApplication sharedApplication].statusBarOrientation) {  
            case UIInterfaceOrientationPortrait:  
                NSLog(@"豎直方向(正)");  
                case UIInterfaceOrientationPortraitUpsideDown:  
                NSLog(@"豎直方向(倒)");  
                _butten.frame = CGRectMake(50, 240, 220, 40);  
                break;  
                case UIInterfaceOrientationLandscapeLeft:  
                case UIInterfaceOrientationLandscapeRight:  
                //設置橫屏時視圖的顯示樣式  
                _butten.frame = CGRectMake(320, 150, 60, 30);  
                break;  
                  
            default:  
                break;  
        }  
    } 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章