내 상황은 this question과 매우 유사합니다. 나는 iPhone이 세로 방향이고 iPad가 Landscape에 있고 어디에서나 appDelegate.window.rootViewController = newScreen;을 사용하여 모든 주요 화면 사이를 전환하는 보편적 인 앱을 가지고 있습니다. iPhone 앱이 완벽하게 작동합니다. iPad 앱은 때로 풍경이 아닌 세로 방향으로 스크린을 던질 것입니다.rootViewController가 설정되었지만 잘못된 방향으로 표시됩니다.
AppDelegate* appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
ViewController* v = nil;
if (IS_IPAD()) {
v = [[ViewController alloc] initWithNibName:@"ViewController-iPad" bundle:nil];
}else{
v = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
}
[appDelegate.window setRootViewController:(UIViewController*)v];
가 나는 또한 this other question에서이 시도 : 다음은 몇 가지 샘플 전이 코드
AppDelegate* appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
ViewController* v = nil;
if (IS_IPAD()) {
v = [[ViewController alloc] initWithNibName:@"ViewController-iPad" bundle:nil];
}else{
v = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
}
[UIView
transitionWithView:appDelegate.window
duration:0.5
options:UIViewAnimationOptionTransitionCrossDissolve
animations:^(void) {
BOOL oldState = [UIView areAnimationsEnabled];
[UIView setAnimationsEnabled:NO];
[appDelegate.window setRootViewController:(UIViewController*)v];
[UIView setAnimationsEnabled:oldState];
}
completion:nil];
그러나 아무것도를 해결하지 않았다.
[appDelegate.window makeKeyAndVisable] 및 [appDelegate.window makeKeyWindow]를 사용하여 올바른 방향으로 '충격을 주길'바랍니다.
이것은 이전에 본 적이없는 뷰 컨트롤러를 전환하는 독특한 방법이지만 작동 할 수 있습니다. 뷰 컨트롤러에 적절한'- (BOOL) shouldAutorotateToInterfaceOrientation :'을 추가 했습니까? 그것은 인터페이스 방향이 결정되는 장소 여야합니다. – mvds
나는 정말로했다. 다음과 같이 보입니다. if (IS_IPAD()) { return UIInterfaceOrientationIsLandscape (interfaceOrientation); } return (interfaceOrientation == UIInterfaceOrientationPortrait); –
흠. 덜 엄격한 VC 전환 방법으로 전환 할 수 있습니다 (예 : 고정 된 (빈)보기 컨트롤러를 사용하고 다양한보기를 모달로 표시합니다. 이렇게하면 인터페이스 방향이 더 안정적으로 고정 될 수 있습니다. – mvds