除了手动编码视图外,IOS – 外部(hdmi)输出只填充一半的屏幕

所以,正如标题所说,我有一个iPad上的HDMI和一个注册屏幕连接的观察者,连接后用户selectres并输出一个视图。

然而,如果我从一个笔尖,甚至从一个程序化的视图控制器加载视图,ipad显示纵向的横向视图(是的,两种情况都设置为横向)。

ExternalViewController *ex = [[ExternalViewController alloc] init]; [externalWindow setRootViewController:ex]; 

做这个:

坏 如果我以编程方式创build视图。 像这样:

 UIView *test = [[UIView alloc] initWithFrame:[externalScreen applicationFrame]]; [test setBackgroundColor:[UIColor whiteColor]]; UILabel *msgLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 40, 100, 30)]; msgLabel.text = @"External!"; [test addSubview:msgLabel]; 

它像某种神奇的梦一样运行:

好

不过,我希望viewcontroller加载(和工作!),所以,StackOverflow,我问你。 有没有人遇到过这个?

编辑:它不用说,共同的感性答案不会得到一个赏金,我是一个修复后,而不是一个解决方法。 在我有限的大脑中,我所能做的就是创build一个方法,根据它的input创build一个视图,并添加作为外部监视器的子视图,很明显,这是一个黑客解决scheme,所以修复是赞赏! 谢谢!

编辑:

 -(id)initWithFrame:(CGRect)_rect { rect = _rect; if (self = [super init]) { externalView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"105.png"]]; externalView.alpha = 0.0; [externalView setFrame:rect]; [externalView setBackgroundColor:[UIColor yellowColor]]; self.view = [[UIView alloc] initWithFrame:rect]; self.view.backgroundColor = [UIColor whiteColor]; return self; } } - (void)loadView { self.view = [[UIView alloc] initWithFrame:rect]; self.view.backgroundColor = [UIColor blackColor]; [self.view addSubview:externalView]; } 

按照要求,这是我加载视图控制器,初始化与外部屏幕的大小。 谢谢

只要在你的UIViewController子类的- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation中返回NO

 // ugly, don't use this in real code if ([UIScreen screens].count == 1) return; // just one screen, eww. // getting the secondary screen UIScreen *screen = [[UIScreen screens] objectAtIndex:1]; __block UIScreenMode *highestWidthMode = NULL; [screen.availableModes enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { UIScreenMode *currentModeInLoop = obj; if (!highestWidthMode || currentModeInLoop.size.width > highestWidthMode.size.width) highestWidthMode = currentModeInLoop; }]; // setting to the highest resolution available screen.currentMode = highestWidthMode; NSLog(@"screen.currentMode = %@", screen.currentMode); screen.overscanCompensation = UIScreenOverscanCompensationScale; // initializing screen secondWindow = [[UIWindow alloc] initWithFrame:[screen bounds]]; [secondWindow setScreen:screen]; // other view is a UIViewController, just remember to return NO in - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation or the iOS will rotate the frame. UIViewController *vc = [[OtherView alloc] initWithNibName:@"OtherView" bundle:nil]; secondWindow.rootViewController = vc; [secondWindow makeKeyAndVisible];