2016-11-25 1 views
0

viewController을 회전하지 않고 장치의 방향을 기준으로 아이콘을 바꿀 프로젝트에서 작업하고 있습니다. 회전 할 수있는 여러 viewController 및 내비게이션 컨트롤러에서 회전 할 수없는 다른 항목이 있습니다.shouldAutorotate = NO이고 세로 방향 만 허용되는 경우 장치 방향을 결정하는 방법은 무엇입니까?

이 구현은 내가 원하는 방식대로 작동합니다. 내 탐색 컨트롤러에서

코드 :

- (BOOL)shouldAutorotate 
{ 
    id currentViewController = self.topViewController; 

    if ([currentViewController isKindOfClass:[ChimpTabBarController class]]) { 
     ChimpTabBarController *tabbarController = (ChimpTabBarController*)currentViewController; 

     if (tabbarController.selectedIndex == 0){ 
      return NO; 
     } 
    } else if ([currentViewController isKindOfClass:[RotationViewController class]] || [currentViewController isKindOfClass:[ChimpBlackoutVC class]] || [currentViewController isKindOfClass:[EditPictureVC class]]) { 
     return NO; 
    } 
    return YES; 
} 



-(UIInterfaceOrientationMask)supportedInterfaceOrientations{ 
    id currentViewController = self.topViewController; 

    UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation; 


    if ([currentViewController isKindOfClass:[ChimpTabBarController class]]) { 
     ChimpTabBarController *tabbarController = (ChimpTabBarController*)currentViewController; 

     if (tabbarController.selectedIndex == 0){ 
      return (UIInterfaceOrientationPortrait | UIInterfaceOrientationPortraitUpsideDown); 
     } 
    } else if ([currentViewController isKindOfClass:[RotationViewController class]] || [currentViewController isKindOfClass:[ChimpBlackoutVC class]] || [currentViewController isKindOfClass:[EditPictureVC class]]) { 
     return (UIInterfaceOrientationPortrait | UIInterfaceOrientationPortraitUpsideDown); 
    } 
    return UIInterfaceOrientationMaskAll; 
} 

밖으로 내 장치에 가고 싶어 회전하는 찾을 수있는 방법이 있지만, 허용되지 않는 이유는 무엇입니까? 내가 화살표 등의 단어 ...의

감사

답변

0

을 방향을 변경할 수 있도록 내가 예상했던 것보다 오히려 빨리하는 방법 나 자신을 발견했다.

UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation; 

을하지만 회전 사용할 수 때 항상 장치의 방향을 요청할 수 있습니다 : 응용 프로그램에 대한

당신이 사용할 수있는

[[UIDevice currentDevice] orientation] 

그런 다음 당신의 ViewController에 당신이 추가를 기기 변경 방향에 대한 관찰자 :

->How to check Device Orientation Change From Portrait To Landscape and Vice-Versa in iPad

희망은 앞으로 사람들을 도울 것입니다.

관련 문제