IOS-外部(hdmi)输出仅占屏幕的一半,手动编码视图时除外

IOS-外部(hdmi)输出仅占屏幕的一半,手动编码视图时除外,ios,ipad,Ios,Ipad,因此,正如标题所说,我在iPad上有一个hdmi,一个观察员注册了屏幕连接,在连接后,用户选择res并输出一个视图 但是,如果我从nib加载视图,甚至从编程视图控制器加载视图,ipad会以纵向显示横向视图(是的,两种情况都设置为横向) 即 这是否: 如果我以编程方式创建视图本身。像这样: UIView *test = [[UIView alloc] initWithFrame:[externalScreen applicationFrame]]; [test setBackgroundColo

因此,正如标题所说,我在iPad上有一个hdmi,一个观察员注册了屏幕连接,在连接后,用户选择res并输出一个视图

但是,如果我从nib加载视图,甚至从编程视图控制器加载视图,ipad会以纵向显示横向视图(是的,两种情况都设置为横向)

这是否:

如果我以编程方式创建视图本身。像这样:

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,我要求您。以前有人见过这个吗

编辑:不言而喻,常见的感性答案不会得到赏金,我想要的是修复,而不是解决办法。在我有限的大脑中,我所能做的就是创建一个方法,根据输入创建一个视图,并补充说,作为外部监视器的子视图,很明显这是一个黑客解决方案,因此修复是值得赞赏的!谢谢

编辑:

-(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];
}

根据要求,这是我加载viewcontroller的方式,使用外部屏幕的大小初始化。谢谢

只需在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];

“纵向横向视图”是否被截断或旋转?我的意思是,如果你像第二个例子中那样添加标签,它是显示在屏幕的左上角,还是以90度角显示在左下角?对不起,应该解释一下。当你在屏幕的一半看到视图时,它是横向的,但是旋转的。因此,如果我添加一个标签,它会显示它随文本从下到上旋转。您是否可以包含“无笔尖”视图控制器的
loadView
方法中的代码,显示如何创建视图,从何处获取外部显示的尺寸等?观察:在顶部示例中,看起来像是将外部视图控制器添加到UIWindow,但第二个视图控制器看起来像是添加到UIScreen?不,在视图控制器的情况下,它被设置为根视图。在视图的情况下,它只是作为子视图添加的。不,尝试了。我相信这个视图真的相信它在横向上输出到必要的屏幕上。
// 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];