视频播放如何横竖屏切换续
2015-08-01 23:50
357 查看
接上篇文章
2 腾讯视频的横竖屏切换的实现方法
首先控制整个viewcontroller的view仅支持默认的竖屏即可
然后添加监测屏幕方向变化的通知
接着在通知的回调方法中操作如下
最后,如果想强制播放器横屏或者竖屏播放,可以这样
OK,大功告成。
PS:demo完整版下载地址为:
https://github.com/wangqi211/VideoPlayDemo.git
2 腾讯视频的横竖屏切换的实现方法
首先控制整个viewcontroller的view仅支持默认的竖屏即可
- (BOOL)shouldAutorotate{ return NO; }
然后添加监测屏幕方向变化的通知
- (void)viewWillAppear:(BOOL)animated{ [super viewWillAppear:animated]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientationHasChange:) name:UIDeviceOrientationDidChangeNotification object:nil]; }
接着在通知的回调方法中操作如下
- (void)orientationHasChange:(NSNotification *)notification{ UIDevice *device = (UIDevice *)notification.object; if(device.orientation == UIInterfaceOrientationLandscapeLeft){ [self rotateToLandscapeLeft]; } else if(device.orientation == UIInterfaceOrientationLandscapeRight){ [self rotateToLandscapeRight]; } else if(device.orientation == UIInterfaceOrientationPortrait){ [self rotateToPortrait]; } } - (void)rotateToFullScreen{ if(SCREEN_WIDTH>SCREEN_HEIGHT){ _videoPlayManageView.frame = CGRectMake(0, 0, SCREEN_HEIGHT, SCREEN_WIDTH); } else{ _videoPlayManageView.frame = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT); } [_videoPlayManageView enterInFullScreen]; } - (void)rotateToLandscapeLeft{ if(_lastOrientationValue==UIInterfaceOrientationLandscapeLeft){ return; } [UIView animateWithDuration:0.3 animations:^{ _videoPlayManageView.transform = CGAffineTransformMakeRotation(-M_PI/2); [self rotateToFullScreen]; } completion:^(BOOL finished) { }]; [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeLeft animated:NO]; _lastOrientationValue = UIInterfaceOrientationLandscapeLeft; } - (void)rotateToLandscapeRight{ if(_lastOrientationValue==UIInterfaceOrientationLandscapeRight){ return; } [UIView animateWithDuration:0.3 animations:^{ _videoPlayManageView.transform = CGAffineTransformMakeRotation(M_PI/2); [self rotateToFullScreen]; } completion:^(BOOL finished) { }]; [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight animated:NO]; _lastOrientationValue = UIInterfaceOrientationLandscapeRight; } - (void)rotateToPortrait{ if(_lastOrientationValue==UIInterfaceOrientationPortrait){ return; } [[UIApplication sharedApplication] setStatusBarHidden:NO]; [UIView animateWithDuration:0.3 animations:^{ _videoPlayManageView.transform = CGAffineTransformIdentity; _videoPlayManageView.frame = _normalScreenFrame; [_videoPlayManageView exitFromFullScreen]; } completion:^(BOOL finished) { }]; [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait animated:NO]; _lastOrientationValue = UIInterfaceOrientationPortrait; }
最后,如果想强制播放器横屏或者竖屏播放,可以这样
- (void)videoPlayManageViewExitFullScreenButtonTapped{ [self rotateToPortrait]; } - (void)videoPlayManageViewEnterFullScreenButtonTapped{ [self rotateToLandscapeRight]; }
OK,大功告成。
PS:demo完整版下载地址为:
https://github.com/wangqi211/VideoPlayDemo.git
相关文章推荐
- DVI 视频接口图文解析
- C#实现字体旋转的方法
- 基于jQuery实现的旋转彩圈实例
- C++实现一维向量旋转算法
- C#调用mmpeg进行各种视频转换的类实例
- C#获取视频某一帧的缩略图的方法
- 使用JavaScript实现旋转的彩圈特效
- C#中图片旋转和翻转(RotateFlipType)用法分析
- 显示youtube视频缩略图和Vimeo视频缩略图代码分享
- Android Tween动画之RotateAnimation实现图片不停旋转效果实例介绍
- Swift中实现点击、双击、捏、旋转、拖动、划动、长按手势的类和方法介绍
- PHP使用ffmpeg给视频增加字幕显示的方法
- PHP实现将视频转成MP4并获取视频预览图的方法
- C++实现优酷土豆去视频广告的方法
- PHP简单获取视频预览图的方法
- asp.net 页面中添加普通视频的几种方式介绍
- Android实现屏幕旋转方法总结
- Android获取SD卡上图片和视频缩略图的小例子
- php使用memcoder将视频转成mp4格式的方法
- 基于js与flash实现的网站flv视频播放插件代码