2014-09-25 6 views
17

빈 응용 프로그램이 있고 스토리 보드 나 xib가 없습니다. 숨겨진 상태 표시 줄과 가로 방향 만 지원하고 싶습니다. 다시 말하지만, 코드 내에서만 변경 작업을 수행하지 않고 Info.plist를 건드리지 마십시오. 가로 방향을 사용할 때 UIWindow 크기가 잘못되었습니다.

문제는 내가 유일하게 지원되는 방향 풍경이다라는 컨트롤러와의 UIWindow를 생성합니다. 이 경우 내 UIWindow는 세로 모드의 차원에서 만들어지고 회전하지 않습니다. 예상되는 결과는 완전히 시안 색 인 화면입니다. 이것은 내 컨트롤러

#import "AppDelegate.h" 
#import "AppViewController.h" 

@implementation AppDelegate 

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 
    self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds]; 
    self.window.backgroundColor = [UIColor cyanColor]; 
    self.window.rootViewController = [[AppViewController alloc] init]; 
    [self.window makeKeyAndVisible]; 
    return YES; 
} 

@end 

:

Broken UIWindow

내 대표입니다

#import "AppViewController.h" 

@implementation AppViewController 

- (BOOL)shouldAutorotate { 
    return YES; 
} 

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation { 
    return UIInterfaceOrientationLandscapeLeft; 
} 

- (BOOL)prefersStatusBarHidden { 
    return YES; 
} 

- (NSUInteger)supportedInterfaceOrientations { 
    return UIInterfaceOrientationMaskLandscape; 
} 

@end 

나는 그렇게 해봤 무엇 제가 후 rootViewController를 설정하면

makeKeyAndVisible을 호출하면 처음에는 모든 것이 작동하는 것 같습니다.

self.window.backgroundColor = [UIColor cyanColor]; 
[self.window makeKeyAndVisible]; 
self.window.rootViewController = [[AppViewController alloc] init]; 

아직 몇 가지 문제가 있습니다. 우선 매우 취약한 것 같아서 나는 이것을 좋아하지 않습니다.

Broken GLKViewController

그것은 상태 표시 줄이 아닌 보이는 같은 : 두 번째 문제는 다음과 같은 결과를 얻을 rootViewController로 GLKViewController을 설정하는 더 복잡한 응용 프로그램 (예상 왼쪽에는 검은 색 영역 없을 것)이다 일찌감치 숨겨져 있습니다. , _UIApplicationHandleEventFromQueueEvent 예상치 못한 닐 창 몇몇 제스처 인식기 활성 및 GLKViewController에 흑색 영역을 클릭하면 다음 로그 메시지 산출 :

2014년 9월 25일 13 : 20 : 42.170 StackOverflowExample [107,907 6971]를 _windowServerHitTestWindow : UIClassicWindow : 0x7fa20b805e00; frame = (0 0; 375 667); userInteractionEnabled = NO; 제스처 인식기 = NSArray : 0x7fa20b80a620; layer = UIWindowLayer : 0x7fa20b806890

또한 빈 UIViewController를 첨부하고 내보기를 하위보기로 추가하는 등 다양한 다른 변경 작업을 수행했습니다. 이 경우 내보기가 올바르지 만 창은 여전히 ​​잘못된 치수를 사용하고 있습니다.

내 View Controller의 supportedInterfaceOrientations 메소드를 재정의하지 않으면 모든 것이 올바르게 회전합니다. 그러나 그것은 물론 내가 원하는 것이 아닙니다.

이 문제를 자신했다 Info.plist 파일에 추가 속성을 추가 할 수있는 시작 화면을 추가 할 때 문제가 해결

답변

24

당신은 모드 UIScreen은 (아이폰 OS 8 일부 캐시를 만들면서 당신이 응용 프로그램 스위치 패널에없는이 응용 프로그램이있는 경우에만) 아이폰 OS 8 세로 경계를 가지고 세로에서 풍경 응용 프로그램을 실행합니다. makeKeyAndVisible으로 창을 표시하더라도 프레임이 변경되지 않습니다. 그러나 AppViewController에 따라 [UIScreen mainScreen].bounds이 변경됩니다.

#import "AppDelegate.h" 
#import "AppViewController.h" 

@implementation AppDelegate 

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 
    // Portrait bounds at this point 
    self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds]; 

    self.window.backgroundColor = [UIColor cyanColor]; 
    self.window.rootViewController = [[AppViewController alloc] init]; 
    [self.window makeKeyAndVisible]; 
    return YES; 
} 

@end 

는 그럼 나는 그것이 아이폰 OS 8 버그이라고 생각 [self.window makeKeyAndVisible]

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 
    self.window = [UIWindow new]; 
    self.window.backgroundColor = [UIColor cyanColor]; 
    self.window.rootViewController = [[AppViewController alloc] init]; 
    [self.window makeKeyAndVisible]; 

    // Here it is 
    self.window.frame = [UIScreen mainScreen].bounds; 
    return YES; 
} 

후 윈도우의 프레임을 변경할 수 있습니다.

+1

공유해 주셔서 감사합니다. 방금하는 방법을 알아 내려고 많은 시간을 보냈습니다. –

+0

iOS8.1에서는 Swift를 사용하여 UIWindow의 너비와 높이에 작은 부분을 추가하여 여기에서 설명한대로 내 문제를 해결해야했습니다. http://stackoverflow.com/a/26452679/190599 – CodeReaper

+0

대단히 감사합니다. 제비. –

0

, 난 당신이 코드를 통해 추가 할 수 있는지 확실하지 않습니다 하지만, 난 단지 사실

<key>UILaunchStoryboardName</key> 
<string>Launch Screen</string> 

난 당신이 (어떤 값) 단지 키를 사용할 수있는 경우 XIB 파일을 추가 할 필요가 있다고 생각하지 않습니다이의 Info.plist + 시작 화면 XIB 파일과 함께 작동하도록 관리 plist에서 작동해야합니다.

+0

불행히도 나를 위해하지 않았습니다. –

8

세로 전용 앱의 경우 비슷한 문제가있었습니다.

내가 전에, 당신은 setStatusBarOrientation:animated: 방법 UIInterfaceOrienationLandscapeLeft (또는 오른쪽)를 사용한다 귀하의 경우에는 UIWindow

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 
    // Init my stuff 
    // ... 

    // Prepare window 
    [application setStatusBarOrientation:UIInterfaceOrientationPortrait animated:NO]; // prevent start orientation bug 
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; 
    [self.window makeKeyAndVisible]; 
    return YES; 
} 

의 인스턴스를 상태 표시 줄의 방향을 설정하여 문제를 해결.

희망이 있으면 도움이됩니다.

+0

화려한! 다른 솔루션은 작동하지 않았습니다. – RawMean

0

여기 또는 다른 곳에 게시 된 솔루션은 없습니다.

그러나이 문제는 Storyboards에서 발생하지 않는 것으로 나타났습니다. 대체 솔루션은 xib에서 벗어나는 것입니다. (이 사실은 안타깝게도 애플이 문제를 심각하게 받아들이지 않을 것임을 의미한다.)