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