WebRTC始终是正的图像解决

1 篇文章 0 订阅

iOS集成WEBRTC后,使用自带获取视频方法,
出现问题描述:
关闭自动锁屏后上下左右旋转屏幕,显示摄像头始终自动旋转是正的图像,不符合项目需求,经研究编译源码查资料,最终在 StackOverflow 找到一篇文章讲可以随时监测设备方向,代码更换设备方向提供了思路,
(因为按这个需要计时器小于0.2s进行检测设置,耗费资源,转换思路在获取设备转换方向时进行重设设备方向)

最终解决方案思路:
在获取设备方向通知中,手动设置设备方向,
主要代码如下

- (void)viewDidLoad {
    [super viewDidLoad];

    /// 禁止总是正方向, 刚进入页面设置初始化方向
      NSNumber *orientationTarget = [NSNumber numberWithInt:UIInterfaceOrientationLandscapeRight];
      [[UIDevice currentDevice] setValue:orientationTarget forKey:@"orientation"];
    /// 注册获取设备方向通知
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(deviceOrientationChange:) name:UIDeviceOrientationDidChangeNotification object:nil];
}


/// 设备方向通知实现
- (void)deviceOrientationChange:(NSNotification *)notification {
    UIDeviceOrientation  orient = [UIDevice currentDevice].orientation;
    switch (orient) {
        case UIDeviceOrientationPortrait:
            NSLog(@"竖屏");
//            break;
        case UIDeviceOrientationLandscapeLeft:
            NSLog(@"左");
//            break;
        case UIDeviceOrientationPortraitUpsideDown:
            NSLog(@"颠倒");
//            break;
        case UIDeviceOrientationLandscapeRight:
            NSLog(@"右");
            break;
        default:
            break;
    }
    /// 手动设置设备方向,
    NSNumber *orientationTarget = [NSNumber numberWithInt:UIInterfaceOrientationLandscapeRight];
    [[UIDevice currentDevice] setValue:orientationTarget forKey:@"orientation"];
}



/// 退出WEBRTC页面
-(void)stopAction
{
    /// 退出WEBRTC页面,去掉通知,设置竖屏
      [[NSNotificationCenter defaultCenter] removeObserver:self];
    NSNumber *orientationTarget = [NSNumber numberWithInt:UIInterfaceOrientationPortrait];
    [[UIDevice currentDevice] setValue:orientationTarget forKey:@"orientation"];
}



  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值