2012-11-27 117 views
0

對於我的應用程序,我想讓設備旋轉,但顛倒。這工作正常。不過,我想從iOS6設備旋轉限制

景觀專門旋轉停止應用程序左 - >景觀權 - 反之亦然

如果有人想了解情況,這是因爲旋轉弄亂我的佈局,因爲他們每個從一個共同的點旋轉

我的iOS 5,我認爲會的工作,代碼是這樣的:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation { 

    NSLog(@"Rotating"); 
    if((lastOrient == 3 && toInterfaceOrientation == 4) || (lastOrient == 4 && toInterfaceOrientation == 3)){ 
     lastOrient = toInterfaceOrientation; 
     return NO; 
    } 

    lastOrient = toInterfaceOrientation; 
    return YES; 

} 

其中3 =景觀左,4 =景觀權

有關如何使用iOS6執行此操作的任何建議?或者完全不同的解決方案?

回答

0

好吧,我在這裏回答了我的問題:

好消息是,肯定是有辦法做到這一點!所以繼承人的基本知識:

在iOS6中,它取決於appDelegate來處理應用程序是否可以一般旋轉。然後,當設備獲得旋轉信號時,它會要求您的視圖支持其方向。這是我實現我的代碼的地方。實際上,shouldAutorotate()在解決方案中不起作用。

所以我創建了一個變量來跟蹤的最後的方向,並改變它在

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

這樣我可以比較的方向

-(NSUInteger)supportedInterfaceOrientations 
{ 
    NSLog(@"Last Orient = %d", lastOrient); 
    NSUInteger orientations = UIInterfaceOrientationMaskPortrait; 

    if (lastOrient != 3 && lastOrient != 4) { 
     NSLog(@"All good, rotate anywhere"); 
     return UIInterfaceOrientationMaskAllButUpsideDown; 
    } 
    else if(lastOrient == 3){ 
     orientations |= UIInterfaceOrientationMaskLandscapeRight; 
     NSLog(@"Can only rotate right"); 
    } 
    else if(lastOrient == 4){ 
     orientations |= UIInterfaceOrientationMaskLandscapeLeft; 
     NSLog(@"Can only rotate left"); 
    } 

    return orientations; 
} 

似乎爲我工作。有點破解,但它做它需要做的事

1

shouldAutorotateToInterfaceOrientation在ios6中已棄用。使用這個:

- (BOOL)shouldAutorotate { 

UIInterfaceOrientation orientation = [[UIDevice currentDevice] orientation]; 

if (lastOrientation==UIInterfaceOrientationPortrait && orientation == UIInterfaceOrientationPortrait) { 
return NO; 

} 

return YES; 
} 

未測試此代碼。你可以得到更多的信息並對這些帖子: shouldAutorotateToInterfaceOrientation is not working in iOS 6 shouldAutorotateToInterfaceOrientation not being called in iOS 6

+0

顯然你可以包括兩個實現(shouldAutorotateToOrientation和shouldAutorotate),它應該從ios6級聯下來 – dmoss18