(iOS开发)iPad通过lighting转HDMI连接电视,电视屏幕不能满屏有黑边的解决方案

目前大部分电视都是16:9的显示屏,史诗级大屁股显示屏已经很少见了。iPad的屏幕是4:3的,当用iPad连接电视后,因为比例不一样,电视屏幕左右两侧会有黑边,看视频的话相当不爽。有人说用遥控器设置,公司电脑全部是海信,我找遍了菜单里所有的选项也没能去掉黑边满屏显示,所以只能从代码上下手了。

下面三个监听可以监控外接显示屏的连接情况
[[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(screenDidConnectNotification:) name: UIScreenDidConnectNotification object: nil];
[[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(screenDidDisconnectNotification:) name: UIScreenDidDisconnectNotification object: nil];
[[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(screenModeDidChangeNotification:) name: UIScreenModeDidChangeNotification object: nil];
可以用下面的方法找到外接屏
//[UIScreen screens] 返回一个数组,包含本机和外连的所有screen,数组中第一个对象肯定是 [UIScreen mainScreen]
UIScreen *external = [[UIScreen screens] objectAtIndex: 1];//external就是电视的screen
屏幕模式,也就是屏幕的大小和像素
UIScreenMode *preferedMode = external.preferredMode;//最合适电视的屏幕模式
UIScreenMode *maxScreenMode = nil;//电视支持的最大的屏幕模式
for(int i = 0; i < [[external availableModes] count]; i++) {
    UIScreenMode *current = [[[[UIScreen screens] objectAtIndex:1] availableModes] objectAtIndex: i];
    if (current.size.width > max.width) {
        max = current.size;
        maxScreenMode = current;
      }
 }
external.currentMode = maxScreenMode;
//我测试的preferedMode和maxScreenMode一直是相同的,为保险还是用的maxScreenMode
屏幕的过扫描补偿(UIScreenOverscanCompensation)
typedef NS_ENUM(NSInteger, UIScreenOverscanCompensation) {
    UIScreenOverscanCompensationScale,                           // the final composited framebuffer for the screen is scaled to avoid clipping
    UIScreenOverscanCompensationInsetBounds,                     // the screen's bounds will be inset in the framebuffer to avoid clipping. no scaling will occur
    UIScreenOverscanCompensationNone NS_ENUM_AVAILABLE_IOS(9_0), // no scaling will occur. use overscanCompensationInsets to determine the necessary insets to avoid clipping
    UIScreenOverscanCompensationInsetApplicationFrame NS_ENUM_DEPRECATED_IOS(5_0, 9_0, "Use UIScreenOverscanCompensationNone") = 2,
};
//只有电视屏幕是过扫描时才有效果
external.overscanCompensation = UIScreenOverscanCompensationScale;
把iPad屏幕上的内容处理成全屏并传输到电视
大体思路就是实时截屏给external显示,上次写到这就给忘了,过了很久了就不往下写了,有需要的小伙伴可以联系我。

你可能感兴趣的:((iOS开发)iPad通过lighting转HDMI连接电视,电视屏幕不能满屏有黑边的解决方案)