开发者社区> 问答> 正文

iOS推流横屏方案有什么建议?

iOS推流横屏方案有什么建议?

展开
收起
保持可爱mmm 2020-03-29 22:36:21 447 0
1 条回答
写回答
取消 提交回答
  • 注意:目前 SDK 的横屏推流需要在推流界面的 Controller 中将 iPhone 竖屏锁定(即只允许 Portrait 一个方向),因为推流 SDK 是对采集到的视频帧做的旋转,不是对 view 做的旋转。

    横屏模式下,如果有需求的话,需要对 UI 做一套横屏的适配,在此套适配方案中,不需要对预览 view 做旋转。例如:如果预览画面是全屏,横屏模式下,则不需要对预览画面的 view 做任何更改,只需要对页面上其他的如点赞 button 做一下 frame 的变化。 操作步骤

    检测设备方向
    
    [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleDeviceOrientationDidChange:) name:UIDeviceOrientationDidChangeNotification object:nil];
    					
    
    设备方向回调中设置横屏推流还是竖屏推流
    
    - (void)handleDeviceOrientationDidChange:   (UIInterfaceOrientation)interfaceOrientation {
    
     UIDevice *device = [UIDevice currentDevice] ;
     switch (device.orientation) {
         case UIDeviceOrientationFaceUp:
             NSLog(@"屏幕朝上平躺");
             break;
    
         case UIDeviceOrientationFaceDown:
             NSLog(@"屏幕朝下平躺");
             break;
    
         case UIDeviceOrientationUnknown:
             NSLog(@"未知方向");
             break;
    
         case UIDeviceOrientationLandscapeLeft: {
             NSLog(@"屏幕向左横置");
             // 横屏推流
             [self destroySession];     // 销毁推流
             // 建议加一个loading  因为销毁推流在重新推流会关闭在重新开启摄像头采集
             _isScreenHorizontal = YES;  // 全局变量  横屏置为YES
             [self testPushCapture];    // 重新推流
         }
             break;
    
         case UIDeviceOrientationLandscapeRight:
             NSLog(@"屏幕向右橫置");
             break;
    
         case UIDeviceOrientationPortrait: {
             NSLog(@"屏幕直立");
             // 竖屏推流
             [self destroySession];     // 销毁推流
             _isScreenHorizontal = NO;  // 全局变量  横屏设置为NO
             [self testPushCapture];    // 重新推流
         }
             break;
    
         case UIDeviceOrientationPortraitUpsideDown:
             NSLog(@"屏幕直立,上下顛倒");
             break;
    
         default:
             NSLog(@"无法辨识");
             break;
     }
    
    }
    					
    
    注销 Device
    
    - (void)dealloc{
     [[NSNotificationCenter defaultCenter] removeObserver:self];
     [[UIDevice currentDevice]endGeneratingDeviceOrientationNotifications];
    }
    
    2020-03-29 22:40:16
    赞同 展开评论 打赏
问答分类:
问答地址:
问答排行榜
最热
最新

相关电子书

更多
手淘iOS性能优化探索 立即下载
From Java/Android to Swift iOS 立即下载
深入剖析iOS性能优化 立即下载