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

时间:2011-11-11 17:52:18

标签: ios ipad

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

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

即。

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

这样做:

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

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

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

good

但是我希望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的方式,初始化外部屏幕的大小。谢谢

1 个答案:

答案 0 :(得分:4)

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

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