2012-08-23 19 views
0

爲什麼UIInterfaceOrientation總是返回正確的?
當我完成旋轉時,總是在右邊結束,爲什麼?
PS:我只想景觀

下面是代碼爲什麼UIInterfaceOrientation總是返回正確的?

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{ 
    switch (interfaceOrientation) 
    { 
     case UIInterfaceOrientationLandscapeLeft: 
      NSLog(@"Is Left"); 
     case UIInterfaceOrientationLandscapeRight: 
      NSLog(@"Is Right"); 
     default: ; 
    } 

    return UIInterfaceOrientationIsLandscape(interfaceOrientation); 
} 

- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation 
{ 
    switch (fromInterfaceOrientation) 
    { 
     case UIInterfaceOrientationLandscapeLeft: 
      NSLog(@"From Left"); 
     case UIInterfaceOrientationLandscapeRight: 
      NSLog(@"From Right"); 
     default: ; 
    } 
} 

這裏是LOG

2012-08-23 17:45:28.074 Simulador 360[323:707] Is Right 
2012-08-23 17:45:28.126 Simulador 360[323:707] Is Right 
2012-08-23 17:45:28.131 Simulador 360[323:707] Is Left 
2012-08-23 17:45:28.132 Simulador 360[323:707] Is Right 
2012-08-23 17:45:28.138 Simulador 360[323:707] Is Left 
2012-08-23 17:45:28.140 Simulador 360[323:707] Is Right 
2012-08-23 17:45:31.160 Simulador 360[323:707] Is Right 
2012-08-23 17:45:31.167 Simulador 360[323:707] Is Right 
2012-08-23 17:45:31.977 Simulador 360[323:707] From Left 
2012-08-23 17:45:31.980 Simulador 360[323:707] From Right 
2012-08-23 17:45:35.684 Simulador 360[323:707] Is Left 
2012-08-23 17:45:35.687 Simulador 360[323:707] Is Right 
2012-08-23 17:45:35.691 Simulador 360[323:707] Is Left 
2012-08-23 17:45:35.693 Simulador 360[323:707] Is Right 
2012-08-23 17:45:36.502 Simulador 360[323:707] From Right 

回答

0

你缺少break在你switch語句。在不調用break的情況下,執行將繼續執行到下一個案例,所以如果您的案例中的界面方向評估爲左側,則將執行左側和右側大小寫塊。

修復此通過在您的每一個案件的末尾插入break

switch (interfaceOrientation) 
{ 
    case UIInterfaceOrientationLandscapeLeft: 
     NSLog(@"Is Left"); 
     break; 
    case UIInterfaceOrientationLandscapeRight: 
     NSLog(@"Is Right"); 
     break; 
    default: ; 
} 
+0

我發現,當我看到它在devblog網站奇怪。有些東西我仍然習慣於Objective-C。感謝您的時間來糾正我的錯誤,毛病! –