2014-10-16 10 views
2

내 앱이 두 번째 화면 (외부 모니터)을 구동하지만 회전과 관련하여 '이상한'현상이 발생합니다 (iOS7에서는 발생하지 않는 사항)iOS8.0 및 8.1의 두 번째 UIScreen에 자동 회전 문제

가로 방향으로 앱을 시작한 다음 두 번째 화면을 연결 한 다음 홈 버튼을 눌러 앱을 백그라운드에 놓은 다음 앱을 다시 연 다음 두 번째 화면 (모니터에 부착 됨)이 90도 회전합니다. 화면을 절반 만 사용합니다. 이후에 회전하는 횟수가 줄어 듭니다.

저는 이것이 버그라고 확신합니다.하지만 달리 알게되어 기쁩니다. 다음은 간단한 단일보기 응용 프로그램에서 코드를 재현하는 코드입니다.

감사

@interface AppDelegate() 

@property (nonatomic, strong) UIWindow* externalWindow; 

@end 

@implementation AppDelegate 


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(screenDidConnect:) name:UIScreenDidConnectNotification object:nil]; 

    UIScreen* externalScreen = ([UIScreen screens].count > 1 ? [[UIScreen screens] objectAtIndex:1] : nil); 
    if (externalScreen) 
    { 
     [self setupExternalScreen:externalScreen]; 
    } 

    return YES; 
} 

- (void) screenDidConnect:(NSNotification *)aNotification 
{ 
    UIScreen* externalScreen = (UIScreen*)aNotification.object; 
    [self setupExternalScreen:externalScreen]; 
} 

- (void)setupExternalScreen:(UIScreen*)externalScreen 
{ 
    externalScreen.currentMode = externalScreen.preferredMode; 

    self.externalWindow = [[UIWindow alloc] initWithFrame:externalScreen.bounds]; 
    self.externalWindow.screen = externalScreen; 
    self.externalWindow.clipsToBounds = YES; 
    self.externalWindow.hidden = NO; 
    [self.externalWindow makeKeyAndVisible]; 

    UIViewController* externalViewController = [[UIViewController alloc] initWithNibName:nil bundle:nil]; 
    externalViewController.view.backgroundColor = [UIColor redColor]; 
    self.externalWindow.rootViewController = externalViewController; 
} 
@end 

답변

5

확인 -를 해결했습니다.

대신

self.externalWindow.rootViewController = externalViewController; 

을 설정하는 것이 아니라, 단지 윈도우의 서브 뷰와 뷰를 추가

self.externalViewController.view.frame = self.externalWindow.frame; 
[self.externalWindow addSubview:self.externalViewController.view]; 

내가보기를 추측 (뷰 컨트롤러 객체에 대한 참조를 유지하는 기억) 컨트롤러 문제가 혼란스러워졌습니다 .....

+0

또 다른 실수를 해결하기 위해 변환 - 외부 UIWindow '키'를하지 않는다 -는 첫 번째 응답자 물건을 많이 망쳐 놨어요. – Scotty

0

작동하는 다른 해결책 : 윈도우의 루트보기 co에서 supportedInterfaceOrientationsshouldAutorotate을 덮어 씁니다. ntroller :

- (NSUInteger)supportedInterfaceOrientations 
{ 
    return UIInterfaceOrientationMaskPortrait; 
} 

- (BOOL)shouldAutorotate 
{ 
    return NO; 
} 
0

난 그냥 UIWindow는 그것을

CGRect frame = screen.bounds; 

if (!self.secondWindow) { 
    UIWindow *extWindow = [[UIWindow alloc] initWithFrame:frame]; 
    self.secondWindow = extWindow; 
} 

if ([[[UIDevice currentDevice] systemVersion] integerValue] == 8) { 
    CGFloat magicAmount = (frame.size.width - frame.size.height)/2; 
    if ([UIDevice currentDevice].orientation == UIDeviceOrientationLandscapeRight) { 
     float rotation = M_PI_2; 
     self.secondWindow.transform = CGAffineTransformTranslate(CGAffineTransformMakeRotation(rotation), magicAmount, magicAmount); 
    } 
    else if ([UIDevice currentDevice].orientation == UIDeviceOrientationLandscapeLeft) { 
     float rotation = -M_PI_2; 
     self.secondWindow.transform = CGAffineTransformTranslate(CGAffineTransformMakeRotation(rotation), -magicAmount, -magicAmount); 
    } 
}