我的应用程序驱动第二个屏幕(外部显示器),但我看到一些关于旋转的“奇怪”事情(在 iOS7 上不会发生的事情)
如果我以横向启动应用程序(并连接第二个屏幕)然后点击主页按钮将应用程序置于后台,然后重新打开应用程序然后第二个屏幕(连接到显示器)旋转 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