3

여기에 많은 질문을 던지기는했지만 저는 지난 며칠 동안 다른 해결책을 찾기 위해 인터넷을 수색하는데 보냈습니다. 아무리 노력해도 아무 것도 보이지 않습니다. 작업.iOS - 다른보기 컨트롤러에 대한 다른 화면 방향

편집 : 는

내가 (나는 현재 iOS6의 지원에 대해 걱정하지 않는다, 그러나이 좋을 것이다)를 가지고있는 것을 나타내는 iOS7에 응용 프로그램을 가지고 ... 여전히 운이뿐만 아니라 this solution을 시도하지 측면에서 슬라이드하는 메뉴가있는 루트보기 컨트롤러 (구체적으로 this one)를 사용하면 다른 화면을 전환 할 수 있습니다. 선택된 화면은 네비게이션 컨트롤러에로드되고 네비게이션 컨트롤러와 스크린의 뷰 컨트롤러 사이에는 "모달 (modal)"유형의 세그가 있습니다 (처음에 나타나는 화면은 제외하고 루트보기 컨트롤러와 관계가 있습니다). 나는 또한 "밀어 넣기 (push)"같은 결과로 이것을 시도했다. 이러한 화면 중 하나는 가로 모드로만 표시되어야하고 나머지는 세로로만 표시되어야합니다. 나는 다음과 같은 구현 한 내 네비게이션 뷰 컨트롤러에서

- (void)awakeFromNib 
{ 
    self.contentViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"contentController"]; 
    self.menuViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"menuController"]; 
} 

-(NSUInteger)supportedInterfaceOrientations 
{ 
    if (self.contentViewController) 
     return [self.contentViewController supportedInterfaceOrientations]; 

    return UIInterfaceOrientationMaskPortrait; 
} 

-(BOOL)shouldAutorotate 
{ 
    return YES; 
} 

:

이 목적을 위해

, 내 루트 뷰 컨트롤러에서 나는 다음과 같은 구현했습니다

-(BOOL)shouldAutorotate 
{ 
    return YES; 
} 
-(NSUInteger)supportedInterfaceOrientations 
{ 
    return [self.topViewController supportedInterfaceOrientations]; 
} 
-(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation 
{ 
    return [self.topViewController preferredInterfaceOrientationForPresentation]; 
} 

과의 각

세로 화면보기 컨트롤러를 구현했습니다.

-(NSUInteger)supportedInterfaceOrientations 
{ 
    return UIInterfaceOrientationMaskPortrait; 
} 
-(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation 
{ 
    return UIInterfaceOrientationPortrait; 
} 

가로 모드 화면 :

- (NSUInteger) supportedInterfaceOrientations 
{ 
    return UIInterfaceOrientationMaskLandscape; 
} 
-(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation 
{ 
    return UIInterfaceOrientationLandscapeLeft; 
} 

앱의 첫 번째 화면은 인물입니다. 무슨 일이 일어나면 앱이 세로 모드로로드되고 다른 방향으로 회전하지 않습니다 (위대함). 그러나! 가로 화면을로드하면 세로 모드로로드되고 장치를 가로 모드로 회전 할 때만 회전되어 가로 모드로 고정됩니다. 그리고 일단 초상화 화면으로 다시 전환하면 가로 모드로로드되고 장치를 세로 방향으로 회전 할 때만 회전 및 세로 모드로 잠겨 어떤 이유로 화면이 매우 좁아집니다 ...

-(void)viewWillAppear:(BOOL)animated{ 
    [super viewWillAppear:animated]; 

    CGRect screenRect = [[UIScreen mainScreen] bounds]; 
    [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeLeft]; 
    CGAffineTransform landscapeTransform = CGAffineTransformMakeRotation(degreesToRadian(270)); 
    landscapeTransform = CGAffineTransformTranslate(landscapeTransform, 0.0, 0.0); 
    [self.navigationController.view setTransform:landscapeTransform]; 
    self.navigationController.view.bounds = CGRectMake(0.0, 0.0, screenRect.size.height, screenRect.size.width); 
} 

-(void)viewWillDisappear:(BOOL)animated{ 
    [super viewWillDisappear:animated]; 

    CGRect screenRect = [[UIScreen mainScreen] bounds]; 
    [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait]; 
    CGAffineTransform landscapeTransform = CGAffineTransformMakeRotation(degreesToRadian(0)); 
    landscapeTransform = CGAffineTransformTranslate(landscapeTransform, 0.0, 0.0); 
    [self.navigationController.view setTransform:landscapeTransform]; 
    self.navigationController.view.bounds = CGRectMake(0.0, 0.0, screenRect.size.width, screenRect.size.height); 
} 
#define degreesToRadian(x) (M_PI * (x)/180.0) 

을 그리고 세로로이보기 컨트롤러의 지원 선호하는 방향을 변경 : 내가 괜찮은 솔루션에 왔 가장 가까운 가로 화면의 뷰 컨트롤러에서이 구현되었다. 기본적으로 전체 앱이 세로 모드로 잠 깁니다. 괜찮아 보이지만 약간 스케치 같아서 나는 "깨끗한"솔루션을 가지고 있고 풍경을 왼쪽과 오른쪽으로 지원할 것입니다. 내가 누락 된 것에 대한 아이디어는?

더 많은 코드를 제공해야하는 경우 말해주십시오. 감사합니다. :)

답변

1

좋아, 단지의 경우이 관심의 사람이이 허용 대답 here 사용하여, 내 솔루션이었다

내가 잃어버린 것은 내 방식에 있었다를 - 풍경은 VC 같은에서 수 없습니다 루트 VC를 포트레이트 VC로 설정하려면 자체 루트 VC가 있어야합니다.

그래서 먼저 스토리 보드에서 풍경 VC를 나머지 부분과 분리했습니다. 이제 완전히 독립적입니다.

+(void)loadController:(UIViewController *)VControllerToLoad andRelease:(UIViewController *)VControllerToRelease 
{ 
    //adjust the frame of the new controller 
    CGRect statusBarFrame = [[UIApplication sharedApplication] statusBarFrame]; 
    CGRect windowFrame = [[UIScreen mainScreen] bounds]; 
    CGRect firstViewFrame = CGRectMake(statusBarFrame.origin.x, statusBarFrame.size.height, windowFrame.size.width, windowFrame.size.height - statusBarFrame.size.height); 
    VControllerToLoad.view.frame = firstViewFrame; 
    //set the new controller as the root controller 
    [[[UIApplication sharedApplication].delegate window] setRootViewController:VControllerToLoad]; 
    //kill the previous view controller 
    [VControllerToRelease.view removeFromSuperview]; 
} 

풍경 VC에서이 코드를 추가 : 다음, 나는 기본적으로 이전 루트 컨트롤러를 새 컨트롤러를로드 루트 컨트롤러로를 설정, 해제는 "뷰 컨트롤러 스위치"방법을 만들어 :

프리젠 테이션 VC를 표시하거나 세로 VC를 되돌릴 때마다 VC 스위치 방법을 사용합니다. 예 :

[AppUtils loadController:landscapeViewController andRelease:portraitNavigationController]; 

그게 전부 야! 이제 모든 것이 매력처럼 작동합니다! :)