2012-10-03 37 views
2

我想允許應轉動的基礎上,目標方位目標取向shouldAutorotate

[[UIDevice currentDevice] orientation] 

然而,在shouldRotate使用時,上面的代碼,保存當前(舊)方向,而不是目標方位

- (BOOL) shouldAutorotate { 

    return YES; 
} 
+0

您是否找到任何解決方案? – strange

回答

0

好吧,我想通了。在shouldAutorotate返回YES總是然後做到這一點:

- (NSUInteger)supportedInterfaceOrientations 
{ 
    if ([UIDevice currentDevice].orientation == UIDeviceOrientationLandscapeLeft) { 
     // Allow if you can 
    } else if ([UIDevice currentDevice].orientation == UIDeviceOrientationPortrait) { 
     // Allow if you can 
    } 
    // so on 
} 
-1

除了是返回

-(BOOL)shouldAutorotate 
{ 
return YES; 
} 

你必須實現

- (NSUInteger)supportedInterfaceOrientations 
{ 
    return UIInterfaceOrientationMaskLandscape; 
} 

不同的掩碼可用是:

UIInterfaceOrientationMaskPortrait 
UIInterfaceOrientationMaskLandscapeLeft 
UIInterfaceOrientationMaskLandscapeRight 
UIInterfaceOrientationMaskPortraitUpsideDown 
UIInterfaceOrientationMaskLandscape 
UIInterfaceOrientationMaskAll 
UIInterfaceOrientationMaskAllButUpsideDown 

您還可以看到:

https://developer.apple.com/library/ios/#documentation/UIKit/Reference/UIViewController_Class/Reference/Reference.html#//apple_ref/occ/instm/UIViewController/supportedInterfaceOrientations

+2

是的,我知道,但那不是一個ansewer我的問題:(如何檢測的目標方向 –

+0

的OP詢問如何檢測的目標方向,我們已經知道我們應該回到YES,如果我們想自動旋轉。 – strange

0
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration 

此方法應該爲你做的伎倆。 toInterfaceOrientation保持目標方向。

+0

你可以請升級答案......那些降低了我的其他答案的人...... – iSaalis