问题
My app supports HDMI Output.
I asked the code for the resolution of the TV and got 1920 x 1080 px for
externalScreen.bounds
OK, everything fine. I've setup my views and tried it on the TV ...
BUT: There were black bars on the bottom / top / sides of the screen though the TV was detected correctly as 1920 x 1080 and my view is also set up correctly?
Why is the format wrong?
P.S. When I mirror the home screen, it also shows the bars, when I watch a video with the Youtube App, the black bars disappear?
Thank you for your help!
Update:
OK, although I got this output in my console:
A new screen got connected: <UIScreen: 0x3439a0; bounds = {{0, 0}, {1920, 1080}}; mode = <UIScreenMode: 0x345240; size = 1920.000000 x 1080.000000>>
... I still get the black frame. I init my view with CGRectMake(0.0f,0.0f,1920.0f,1080.0f)
for test purposes.
This is the view I can see on my screen (note the black bars):
回答1:
The home screen will have black bars because the aspect ratio doesn't match 16:9 (it's 4:3 I think). As far as the external display, check the frame of your main view (the view that's supposed to span the screen). It is probably not set to 1920 x 1080
edit: I used this code for a project where I had to output from an iPad to a 1920 x 1080 display and it worked
- (void) screenDidConnect:(NSNotification *)aNotification
{
NSLog(@"A new screen got connected: %@", [aNotification object]);
//[self printScreenInfo];
UIScreen* newScreen = [aNotification object];
CGRect screenBounds = newScreen.bounds;
if (!self.externalWindow)
{
self.externalWindow = [[UIWindow alloc] initWithFrame:screenBounds];
self.externalWindow.screen = newScreen;
self.externalViewController.view.frame = externalWindow.frame;
[self.externalWindow addSubview:externalViewController.view];
self.externalWindow.hidden = NO;
// Set the initial UI for the window.
// [externalViewController displaySelectionInSecondaryWindow:externalWindow];
}
}
回答2:
externalScreen.overscanCompensation = UIScreenOverscanCompensationInsetApplicationFrame;
回答3:
The setting that works best for most TVs is:
externalScreen.overscanCompensation = UIScreenOverscanCompensationInsetBounds | UIScreenOverscanCompensationInsetApplicationFrame; // this is the same as setting it to 3
Just setting it to UIScreenOverscanCompensationInsetApplicationFrame can cause misalignment of the UIWindow contents.
来源:https://stackoverflow.com/questions/10653285/black-bars-with-hdmi-adapter-on-ipad-2