注意:目前SDK的横屏推流需要在推流界面的Controller中将iPhone竖屏锁定(即只允许Portrait一个方向),因为推流SDK是对采集到的视频帧做的旋转,不是对view做的旋转
[backcolor=transparent]横屏模式下,如果有需求的话,需要对UI做一套横屏的适配,在此套适配方案中,不需要对预览view做旋转,举例:如果预览画面是全屏,横屏模式下,则不需要对预览画面的view做任何更改,只需要对页面上其他的如点赞button做一下frame的变化
步骤:
- [backcolor=transparent][[[backcolor=transparent]UIDevice[backcolor=transparent] currentDevice[backcolor=transparent]][backcolor=transparent] beginGeneratingDeviceOrientationNotifications[backcolor=transparent]];
- [backcolor=transparent][[[backcolor=transparent]NSNotificationCenter[backcolor=transparent] defaultCenter[backcolor=transparent]][backcolor=transparent] addObserver[backcolor=transparent]:[backcolor=transparent]self[backcolor=transparent] selector[backcolor=transparent]:[backcolor=transparent]@selector[backcolor=transparent]([backcolor=transparent]handleDeviceOrientationDidChange[backcolor=transparent]:)[backcolor=transparent] name[backcolor=transparent]:[backcolor=transparent]UIDeviceOrientationDidChangeNotification[backcolor=transparent] [backcolor=transparent]object[backcolor=transparent]:[backcolor=transparent]nil[backcolor=transparent]];
- [backcolor=transparent]-[backcolor=transparent] [backcolor=transparent]([backcolor=transparent]void[backcolor=transparent])[backcolor=transparent]handleDeviceOrientationDidChange[backcolor=transparent]:([backcolor=transparent]UIInterfaceOrientation[backcolor=transparent])[backcolor=transparent]interfaceOrientation [backcolor=transparent]{
- [backcolor=transparent] [backcolor=transparent]UIDevice[backcolor=transparent] [backcolor=transparent]*[backcolor=transparent]device [backcolor=transparent]=[backcolor=transparent] [backcolor=transparent][[backcolor=transparent]UIDevice[backcolor=transparent] currentDevice[backcolor=transparent]][backcolor=transparent] [backcolor=transparent];
- [backcolor=transparent] [backcolor=transparent]switch[backcolor=transparent] [backcolor=transparent]([backcolor=transparent]device[backcolor=transparent].[backcolor=transparent]orientation[backcolor=transparent])[backcolor=transparent] [backcolor=transparent]{
- [backcolor=transparent] [backcolor=transparent]case[backcolor=transparent] [backcolor=transparent]UIDeviceOrientationFaceUp[backcolor=transparent]:
- [backcolor=transparent] [backcolor=transparent]NSLog[backcolor=transparent](@[backcolor=transparent]"屏幕朝上平躺"[backcolor=transparent]);
- [backcolor=transparent] [backcolor=transparent]break[backcolor=transparent];
- [backcolor=transparent] [backcolor=transparent]case[backcolor=transparent] [backcolor=transparent]UIDeviceOrientationFaceDown[backcolor=transparent]:
- [backcolor=transparent] [backcolor=transparent]NSLog[backcolor=transparent](@[backcolor=transparent]"屏幕朝下平躺"[backcolor=transparent]);
- [backcolor=transparent] [backcolor=transparent]break[backcolor=transparent];
- [backcolor=transparent] [backcolor=transparent]case[backcolor=transparent] [backcolor=transparent]UIDeviceOrientationUnknown[backcolor=transparent]:
- [backcolor=transparent] [backcolor=transparent]NSLog[backcolor=transparent](@[backcolor=transparent]"未知方向"[backcolor=transparent]);
- [backcolor=transparent] [backcolor=transparent]break[backcolor=transparent];
- [backcolor=transparent] [backcolor=transparent]case[backcolor=transparent] [backcolor=transparent]UIDeviceOrientationLandscapeLeft[backcolor=transparent]:[backcolor=transparent] [backcolor=transparent]{
- [backcolor=transparent] [backcolor=transparent]NSLog[backcolor=transparent](@[backcolor=transparent]"屏幕向左横置"[backcolor=transparent]);
- [backcolor=transparent] [backcolor=transparent]// 横屏推流
- [backcolor=transparent] [backcolor=transparent][[backcolor=transparent]self[backcolor=transparent] destroySession[backcolor=transparent]];[backcolor=transparent] [backcolor=transparent]// 销毁推流
- [backcolor=transparent] [backcolor=transparent]// 建议加一个loading 因为销毁推流在重新推流会关闭在重新开启摄像头采集
- [backcolor=transparent] _isScreenHorizontal [backcolor=transparent]=[backcolor=transparent] YES[backcolor=transparent];[backcolor=transparent] [backcolor=transparent]// 全局变量 横屏置为YES
- [backcolor=transparent] [backcolor=transparent][[backcolor=transparent]self[backcolor=transparent] testPushCapture[backcolor=transparent]];[backcolor=transparent] [backcolor=transparent]// 重新推流
- [backcolor=transparent] [backcolor=transparent]}
- [backcolor=transparent] [backcolor=transparent]break[backcolor=transparent];
- [backcolor=transparent] [backcolor=transparent]case[backcolor=transparent] [backcolor=transparent]UIDeviceOrientationLandscapeRight[backcolor=transparent]:
- [backcolor=transparent] [backcolor=transparent]NSLog[backcolor=transparent](@[backcolor=transparent]"屏幕向右橫置"[backcolor=transparent]);
- [backcolor=transparent] [backcolor=transparent]break[backcolor=transparent];
- [backcolor=transparent] [backcolor=transparent]case[backcolor=transparent] [backcolor=transparent]UIDeviceOrientationPortrait[backcolor=transparent]:[backcolor=transparent] [backcolor=transparent]{
- [backcolor=transparent] [backcolor=transparent]NSLog[backcolor=transparent](@[backcolor=transparent]"屏幕直立"[backcolor=transparent]);
- [backcolor=transparent] [backcolor=transparent]// 竖屏推流
- [backcolor=transparent] [backcolor=transparent][[backcolor=transparent]self[backcolor=transparent] destroySession[backcolor=transparent]];[backcolor=transparent] [backcolor=transparent]// 销毁推流
- [backcolor=transparent] _isScreenHorizontal [backcolor=transparent]=[backcolor=transparent] NO[backcolor=transparent];[backcolor=transparent] [backcolor=transparent]// 全局变量 横屏设置为NO
- [backcolor=transparent] [backcolor=transparent][[backcolor=transparent]self[backcolor=transparent] testPushCapture[backcolor=transparent]];[backcolor=transparent] [backcolor=transparent]// 重新推流
- [backcolor=transparent] [backcolor=transparent]}
- [backcolor=transparent] [backcolor=transparent]break[backcolor=transparent];
- [backcolor=transparent] [backcolor=transparent]case[backcolor=transparent] [backcolor=transparent]UIDeviceOrientationPortraitUpsideDown[backcolor=transparent]:
- [backcolor=transparent] [backcolor=transparent]NSLog[backcolor=transparent](@[backcolor=transparent]"屏幕直立,上下顛倒"[backcolor=transparent]);
- [backcolor=transparent] [backcolor=transparent]break[backcolor=transparent];
- [backcolor=transparent] [backcolor=transparent]default[backcolor=transparent]:
- [backcolor=transparent] [backcolor=transparent]NSLog[backcolor=transparent](@[backcolor=transparent]"无法辨识"[backcolor=transparent]);
- [backcolor=transparent] [backcolor=transparent]break[backcolor=transparent];
- [backcolor=transparent] [backcolor=transparent]}
- [backcolor=transparent]}
- [backcolor=transparent]-[backcolor=transparent] [backcolor=transparent]([backcolor=transparent]void[backcolor=transparent])[backcolor=transparent]dealloc[backcolor=transparent]{
- [backcolor=transparent] [backcolor=transparent][[[backcolor=transparent]NSNotificationCenter[backcolor=transparent] defaultCenter[backcolor=transparent]][backcolor=transparent] removeObserver[backcolor=transparent]:[backcolor=transparent]self[backcolor=transparent]];
- [backcolor=transparent] [backcolor=transparent][[[backcolor=transparent]UIDevice[backcolor=transparent] currentDevice[backcolor=transparent]][backcolor=transparent]endGeneratingDeviceOrientationNotifications[backcolor=transparent]];
- [backcolor=transparent]}