【iOS】旋轉螢幕,螢幕自適應方向變化

來源:互聯網
上載者:User

標籤:style   blog   http   color   io   os   java   ar   div   

1. iOS有四個方向的旋轉,為了保證自己的代碼能夠支援旋轉,我們必須首先處理一個函數:

Objective-c代碼  
  1. - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {  
  2.   
  3.     return YES;  
  4. }  
 

2. 這個函數時用來確定我們的應用所支援的旋轉方向。如果想要支援每個方向則直接返回YES就行,還可以單獨判斷某一方向:

 

Objective-c代碼  
  1. - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {  
  2.   
  3.     if (interfaceOrientation==UIInterfaceOrientationLandscapeLeft) {  
  4.   
  5.         //left  
  6.   
  7.     }  
  8.   
  9.     if (interfaceOrientation==UIInterfaceOrientationLandscapeRight) {  
  10.   
  11.         //right  
  12.   
  13.     }  
  14.   
  15.     if (interfaceOrientation==UIInterfaceOrientationPortrait) {  
  16.   
  17.         //up  
  18.   
  19.     }  
  20.   
  21.     if (interfaceOrientation==UIInterfaceOrientationPortraitUpsideDown) {  
  22.   
  23.         //down  
  24.   
  25.     }  
  26.   
  27.     return YES;  
  28. }  
  

3. 當然旋轉還有一些函數可觸發:

Objective-c代碼  
  1. //旋轉方向發生改變時  
  2.   
  3. -(void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {  
  4. }  
  5. //視圖旋轉動畫前一半發生之前自動調用  
  6.   
  7. -(void)willAnimateFirstHalfOfRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {  
  8. }  
  9. //視圖旋轉動畫後一半發生之前自動調用  
  10.   
  11. -(void)willAnimateSecondHalfOfRotationFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation duration:(NSTimeInterval)duration {  
  12. }  
  13. //視圖旋轉之前自動調用  
  14.   
  15. -(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {  
  16. }  
  17. //視圖旋轉完成之後自動調用  
  18.   
  19. -(void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {  
  20. }  
  21. //視圖旋轉動畫前一半發生之後自動調用  
  22.   
  23. -(void)didAnimateFirstHalfOfRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {  
  24. }  
  

【iOS】旋轉螢幕,螢幕自適應方向變化

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.