溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

視圖控制器 旋轉(zhuǎn)

發(fā)布時間:2020-06-14 09:14:08 來源:網(wǎng)絡(luò) 閱讀:293 作者:緣起愿落 欄目:開發(fā)技術(shù)


用來控制當前視圖控制器是否支持旋轉(zhuǎn)
- (BOOL)shouldAutorotate  // 自動旋轉(zhuǎn)
{
    return YES;
}



設(shè)置屏幕旋轉(zhuǎn)的方向,系統(tǒng)默認支持三個方向的旋轉(zhuǎn),豎直,左右橫屏.
    UIInterfaceOrientationMaskPortrait 豎直方向 正方向
    UIInterfaceOrientationMaskLandscapeLeft 左橫屏
    UIInterfaceOrientationMaskLandscapeRight 右橫屏
    UIInterfaceOrientationMaskLandscape 左右 橫屏


- (NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskAll;
}



當屏幕將要旋轉(zhuǎn)時觸發(fā)(此時屏幕還未旋轉(zhuǎn))
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
    [super willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration];
}


當屏幕旋轉(zhuǎn)時觸發(fā).
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
 

在該方法中,如果想要在屏幕旋轉(zhuǎn)時添加自己的動畫,在該方法中實現(xiàn).
    [super willAnimateRotationToInterfaceOrientation:toInterfaceOrientation duration:duration];
}



當屏幕旋轉(zhuǎn)完成之后觸發(fā).
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
{
      
    [super didRotateFromInterfaceOrientation:fromInterfaceOrientation];
     旋轉(zhuǎn)之后,繼續(xù)音樂播放,繼續(xù)播放視頻,打開用戶交互.
}


當對視圖控制器上的View布局時重新布局時 觸發(fā).
- (void)viewWillLayoutSubviews
{
    
    [super viewWillLayoutSubviews];

}




   釋放掉暫時不使用的內(nèi)存,供當前程序使用.
- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
      Dispose of any resources that can be recreated.
     當收到內(nèi)存警告時,移除未在當前屏幕顯示的視圖.
    
    判斷是否可以安全的移除控制器的View
     判斷當前視圖控制器的view是否正在屏幕上顯示. self.view.window 是否為nil;
    
  判斷當前視圖控制器的view是否已經(jīng)成功加載. isViewLoaded 視圖是否加載
    
    
    if (!self.view.window && [self isViewLoaded])
    {
         安全移除控制器的view
        self.view = nil;   相等于 [_view release]; _view = nil;
    }
 
    
}



 當屏幕每次旋轉(zhuǎn)時都會觸發(fā)視圖的重新布局方法,為該視圖上的子視圖重新布局.
- (void)layoutSubviews
{
    [super layoutSubviews];
 
    
    對子視圖重新布局.
    根據(jù)屏幕旋轉(zhuǎn)的方向,決定布局的樣式.
    1.獲取屏幕旋轉(zhuǎn)的方向 statusBarOrientation 狀態(tài)條 高度 20
    
    switch ([UIApplication sharedApplication].statusBarOrientation) {
        case UIInterfaceOrientationPortrait:
  
    
            
        case UIInterfaceOrientationPortraitUpsideDown:
    
            break;
        case UIInterfaceOrientationLandscapeLeft:
     
           break;

        case UIInterfaceOrientationLandscapeRight:
            
 
            break;
            
        
        default:
            break;
    }
}

向AI問一下細節(jié)

免責聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI