標籤:style blog http color io os java ar div
1. iOS有四個方向的旋轉,為了保證自己的代碼能夠支援旋轉,我們必須首先處理一個函數:
Objective-c代碼
- - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
-
- return YES;
- }
2. 這個函數時用來確定我們的應用所支援的旋轉方向。如果想要支援每個方向則直接返回YES就行,還可以單獨判斷某一方向:
Objective-c代碼
- - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
-
- if (interfaceOrientation==UIInterfaceOrientationLandscapeLeft) {
-
- //left
-
- }
-
- if (interfaceOrientation==UIInterfaceOrientationLandscapeRight) {
-
- //right
-
- }
-
- if (interfaceOrientation==UIInterfaceOrientationPortrait) {
-
- //up
-
- }
-
- if (interfaceOrientation==UIInterfaceOrientationPortraitUpsideDown) {
-
- //down
-
- }
-
- return YES;
- }
3. 當然旋轉還有一些函數可觸發:
Objective-c代碼
- //旋轉方向發生改變時
-
- -(void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
- }
- //視圖旋轉動畫前一半發生之前自動調用
-
- -(void)willAnimateFirstHalfOfRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
- }
- //視圖旋轉動畫後一半發生之前自動調用
-
- -(void)willAnimateSecondHalfOfRotationFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation duration:(NSTimeInterval)duration {
- }
- //視圖旋轉之前自動調用
-
- -(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
- }
- //視圖旋轉完成之後自動調用
-
- -(void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {
- }
- //視圖旋轉動畫前一半發生之後自動調用
-
- -(void)didAnimateFirstHalfOfRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
- }
【iOS】旋轉螢幕,螢幕自適應方向變化