IOS - 外部(hdmi)输出仅填充屏幕的一半,除非手动编码视图 [英] IOS - External (hdmi) output fills only half the screen except when coding view manually

查看:125
本文介绍了IOS - 外部(hdmi)输出仅填充屏幕的一半,除非手动编码视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,正如标题所说,我在iPad上有一个hdmi,并且注册了屏幕连接的观察者,在连接时用户选择res并输出视图。

So, as the title says, I have an hdmi out on the iPad and an observer registered for screen connections, upon connection the user chooses the res and a view is outputted.

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

However, if I load a view from a nib, or even from a programatic view controller, the ipad shows a landscape view in portrait (yes, both situations are set to landscape).

I.e。

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

这样做:


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

If I create the view itself programatically. like so:

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

它像某种形式的神奇梦想一样:

It runs like some form of magical dream:

但是我想要viewcontroller加载(和工作!)所以,StackOverflow,我问你。有没有人遇到过这个?

However I want the viewcontroller to load (and work!) so, StackOverflow, I ask you. has anyone come across this before?

编辑:不言而喻,常见的敏感答案不会得到赏金,我是在修复之后,而不是解决方法。在我有限的大脑中,我所能想到的就是创建一个基于它的输入创建视图的方法,并将其作为外部监视器的子视图添加,很明显这是一个黑客解决方案,所以修复得到了赞赏!谢谢!

It does go without saying that common sensical answers do not get a bounty, I am after a fix, not a workaround. With my limited brain, all I can think to do is create a method that creates a view based on it's inputs and adds that as a subview of the external monitor, it is clear that this is a hack solution so a fix is appreciated! Thanks!

编辑:

-(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,初始化大小外部屏幕。谢谢

As requested, this is how I am loading the viewcontroller, initialising with the size of the external screen. Thanks

推荐答案

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

Just return NO in - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation in your UIViewController subclass.

// 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];

这篇关于IOS - 外部(hdmi)输出仅填充屏幕的一半,除非手动编码视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆