2011-12-23 4 views
2

iPad 및 iOS 5 이상을 대상으로하는 간단한 앱이 있습니다. 앱이 가로 전용입니다. 자, 저는 iPad 2에서 AirPlay 미러링을 이용하고 싶습니다.iOS 5 AirPlay 화면이 가로로 올바르게 그려지지 않습니다.

나는이 그림 문제를 해결할 수있는 모든 Apple 예제/문서를 따라 왔습니다. 보조 디스플레이가 올바른 방향으로 그려지지 않습니다.

다음은 작은 테스트 응용 프로그램에서 본 출력입니다. 파란색 상자는 전체 화면을 차지해야하는 단순한 UIView이지만 그렇지 않습니다. 가로로 올바르게 그리는 것처럼 보이지만보기가 90도 회전합니다. 어떻게하면 파란색이 TV 하단의 여백을 넘어서는지주의하십시오. enter image description here

필자는 어떻게 든 외부 환경의 ViewController를 강제로 가로로 끌어 올 필요가 있다고 생각하지만 적절한 방법을 알지 못합니다. 이 작업을 수행. 어떤 아이디어? 다음은

는 관련 조각 코드입니다 :

AppDelegate.m :

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

    [self initScreens]; 

    return YES; 
} 

- (void)screenDidConnect:(NSNotification *)note 
{ 
    [self initScreens]; 
} 

- (void)initScreens 
{ 
    if ([[UIScreen screens] count] > 1) 
    { 
     UIScreen *screen = [[UIScreen screens] lastObject]; 

     if (!self.secondaryWindow) 
     { 
      self.secondaryWindow = [[UIWindow alloc] initWithFrame:screen.bounds]; 
      self.secondaryWindow.screen = screen; 
      self.secondaryWindow.hidden = NO; 
     } 

     if (!self.secondaryViewController) 
     { 
      self.secondaryViewController = [[CCKSecondaryViewController alloc] init]; 
     } 

     self.secondaryWindow.rootViewController = self.secondaryViewController; 
    } 
} 

CCKSecondaryViewController.m :이 외부 창

- (void)loadView 
{ 
    UIView *view = [[UIView alloc] initWithFrame:CGRectZero]; 
    view.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth; 
    view.backgroundColor = [UIColor blueColor]; 

    self.view = view; 

    UILabel *label = [[UILabel alloc] initWithFrame:CGRectZero]; 
    label.text = @"Secondary Screen"; 
    [label sizeToFit]; 

    [self.view addSubview:label]; 
    label.center = self.view.center; 
} 

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{ 
    return UIInterfaceOrientationIsLandscape(interfaceOrientation); 
} 
의 rootViewController가

찾을 수 있습니다. 여기에 샘플 응용 프로그램 :

http://dl.dropbox.com/u/360556/AirplayTest.zip

+0

코드가 괜찮아 보입니다 ... 먼저 loadView에서 [super loadView]를 호출해야합니다. – Felix

+0

수정 한 적이 있습니까? 나는 똑같은 문제를 겪고있다. 하지만 iOS 8에서. –

+0

@DustinPfannenstiel 오늘 같은 문제가 발생했습니다.이 게시물이 문제와 일치합니까? http://stackoverflow.com/questions/30040055/uiviewcontroller-displayed-sideways-on-airplay-screen-when-launched-from-landsca – francis

답변

0

그것은 연결된 화면에 세로로 표시합니다. shouldAutorotateToInterfaceOrientation 메소드가 항상 NO을 반환하면이를 정렬해야합니다.

+0

iOS 8에서이 작업을 수행하는 방법에 대한 조언이 필요하십니까? –

관련 문제