iPhone : Landscape 전용에서 첫 번째 AddSubview 이후 UitableViewController는 제대로 회전하지 않습니다.

StackOverflow https://stackoverflow.com/questions/1632117

  •  06-07-2019
  •  | 
  •  

문제

이것에 대한 최소한의 예시 Xcode 프로젝트는 github.

내 uiwindow에서, 내가 두 번째 (그리고 후속) Uitableview를 하위 뷰로 추가하면 제대로 회전하지 않으므로 옆으로 나타납니다. 이것은 시뮬레이터에서만 테스트됩니다. 다음은 당신을위한 작은 코드입니다.

- (void)applicationDidFinishLaunching:(UIApplication *)application {
    ShellTVC* viewA = [[ShellTVC alloc] initWithTitle:@"View A"];
    ShellTVC* viewB = [[ShellTVC alloc] initWithTitle:@"View B"];

    // The first subview added will rotate to landscape correctly. 
    // Any subsequent subview added will not.

    // You may try this by various commentings and rearranging of these two statements.

    [window addSubview:[viewA tableView]];
    [window addSubview:[viewB tableView]];

    [window makeKeyAndVisible];
}

뷰브가 옆으로 나타납니다. ViewB에 대한 AddSubview를 주석하면 Viewa가 올바르게 나타납니다. Viewa에만 해당되면 ViewB가 올바르게 나타납니다.

Ui -Window는 펜촉을 통해이 UabiteViewControllers를 만들지 않습니다.

궁금한 점이 있으면 ShellTVC는 UitableViewController입니다.이 방법을 구현합니다.

- (BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
 return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft);
}

또한 PLIST 파일의 UIINterfaceorientation을 UiinterfaceorientationlandsCapeleft로 설정했습니다.

아마도 관련이 있고 답이 없어서 질문이 될 것입니다 여기 그리고 여기.

도움이 되었습니까?

해결책

나는 이것을 할 수있는 방법을 알아 냈다고 생각합니다.

  1. "Mas
  2. ViewA 또는 ViewB를 번갈아 가려면 DismissModalViewControllerAnimated의 조합을 사용하십시오 : & presentModalViewController : 애니메이션 :이 마스터 뷰 컨트롤러에서.

코드는 다음과 같습니다.

// this doesn't really do much but implement shouldAutorotate...
@interface MasterViewController : UIViewController
@end

@implementation MasterViewController
- (BOOL) shouldAutorotateToInterfaceOrientation(UIInterfaceOrientation)interfaceOrientation {
     return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft);
}
@end

@interface MyAppDelegate : NSObject <UIApplicationDelegate> {
    MasterViewController* masterVC;
    UIViewController* activeTVC;
    UIViewController* onDeckTVC;
}
@end

- (void)applicationDidFinishLaunching:(UIApplication *)application {
    UIViewController* masterVC = [[MasterViewController alloc] init];        
    activeTVC = [[ShellTVC alloc] initWithTitle:@"View A"];
    onDeckTVC = [[ShellTVC alloc] initWithTitle:@"View B"];
    [window addSubview:masterView.view];
    [window makeKeyAndVisible];
    [masterVC presentModalViewController:activeTVC animated:NO];
}

// you would call this to toggle between "View A" and "View B"
- (void)toggleTVC {
    UITableViewController *hold = activeTVC;
    activeTVC = onDeckTVC;
    onDeckTVC = hold;
    [masterVC dismissModalViewControllerAnimated:NO];   
    [masterVC presentModalViewController:activeTVC animated:NO];
}

이것이 왜 작동합니까?

  1. 모든 방향 변경은 뷰가 아닌보기 컨트롤러를 통해 흐릅니다.

  2. 내가 알 수있는 한, 창문에 추가 한 첫 번째보기 또는 하위 뷰는 특별한 소스를 얻습니다. 해당보기에 뷰 컨트롤러가 있으면 창이 파악됩니다.

즉, 첫 번째 하위 뷰에서만이 코드를 생각할 수 있습니다.

[window addSubview:masterVC.view];

이와 같은 일을하는 것처럼 (실제 방법이 아님) :

[window addSubview:masterVC.view withViewController:masterVC];

나는 그것에 대해 더 이상 이해하지 못한다. 나는 첫 번째 하위 뷰로이 작업을 수행 할 수 있지만 다른 사람은 아니지만 극도로 당황합니다. 더 많은 정보를 환영하며 이것이 도움이되었는지 아닌지 알려주세요.

다른 팁

Viewa의 아이로서 Viewb을 추가하면 올바르게 회전 할 것입니다. 이것은 내 프로젝트에 대한 훌륭한 솔루션은 아니지만 유일한 해결 방법 인 것 같습니다.

불행히도 귀하의 하위 뷰는 오리엔테이션 변경이 발생할 때 어떤 방향을 지원하는지에 대해서만 묻습니다.

그래서 나는 그것이 변경되었다는 것을 알면 스택에서 새 뷰 컨트롤러를 푸시하기 전에 방향을 설정하게됩니다.

[[UIDevice currentDevice] setOrientation:UIInterfaceOrientationPortrait]; 

예, 이것은 지원되지 않는 전화입니다.

UIAPPLICATION 객체를 사용하여 특정 장치 방향을 강제 할 수 있습니다.

[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait animated:NO];

예, 여러 XIB를 사용 하여이 문제를 해결해야한다고 생각합니다. 나는 과거에 읽은 책 중 하나를 통해이 솔루션을 본 것을 기억합니다. 그렇지 않다면, 당신은 뷰에서 객체의 번역과 위치를 가지고 놀이요 ... 더 나은 xib가 있습니다.

이것은 작동해야합니다.

- (void)viewDidLoad {
    if (([[UIDevice currentDevice] orientation] == UIDeviceOrientationLandscapeLeft) || 
        ([[UIDevice currentDevice] orientation] == UIDeviceOrientationLandscapeRight)) 

    {
        self.view.frame = CGRectMake(0, 0, 1024, 748);

    } else {
        self.view.frame = CGRectMake(0, 0, 768, 1004);
    }
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top