iOS - 视频播放处理全屏/横屏时候遇见的坑
2017-06-21 11:13
351 查看
视频播放想要全屏,使用shouldAutorotate方法禁止主界面,tabbar控制器横屏,导致push进入播放页面不能横屏的问题。。。
- (BOOL)shouldAutorotate {
return NO;
}
- (UIInterfaceOrientationMask)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskAll;
}
后面解决方法:
- (void)fullScreenClick:(UIButton *)sender {
sender.selected = !sender.selected;
if (sender.isSelected) {
_backButton.hidden = YES;
[self forceOrientationLandscapeLeft];
} else {
_backButton.hidden = NO;
[self forceOrientationPortrait];
}
}
//MARK: -- 强制横屏
- (void)forceOrientationLandscapeLeft
{
AppDelegate *appdelegate=(AppDelegate *)[UIApplication sharedApplication].delegate;
appdelegate.isForcePortrait=NO;
appdelegate.isForceLandscape=YES;
[appdelegate application:[UIApplication sharedApplication] supportedInterfaceOrientationsForWindow:self.view.window];
YNCNavigationViewController *navi = (YNCNavigationViewController *)self.navigationController;
navi.interfaceOrientation = UIInterfaceOrientationMaskLandscape;
navi.interfaceOrientationMask = UIInterfaceOrientationMaskLandscape;
//设置屏幕的转向为横屏
[[UIDevice currentDevice] setValue:@(UIDeviceOrientationLandscapeLeft) forKey:@"orientation"];
//刷新
[UIViewController attemptRotationToDeviceOrientation];
}
//MARK: -- 强制竖屏
- (void)forceOrientationPortrait
{
AppDelegate *appdelegate=(AppDelegate *)[UIApplication sharedApplication].delegate;
appdelegate.isForcePortrait=YES;
appdelegate.isForceLandscape=NO;
[appdelegate application:[UIApplication sharedApplication] supportedInterfaceOrientationsForWindow:self.view.window];
YNCNavigationViewController *navi = (YNCNavigationViewController *)self.navigationController;
navi.interfaceOrientation = UIInterfaceOrientationPortrait;
navi.interfaceOrientationMask = UIInterfaceOrientationMaskPortrait;
//设置屏幕的转向为竖屏
[[UIDevice currentDevice] setValue:@(UIDeviceOrientationPortrait) forKey:@"orientation"];
//刷新
[UIViewController attemptRotationToDeviceOrientation];
}
#import <UIKit/UIKit.h>
@interface AppDelegate : UIResponder <UIApplicationDelegate>
@property (strong, nonatomic) UIWindow *window;
@property (assign , nonatomic) BOOL isForceLandscape;
@property (assign , nonatomic) BOOL isForcePortrait;
@end
AppDelegate.m
-(UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window{
if (self.isForceLandscape) {
return UIInterfaceOrientationMaskLandscape;
}else if (self.isForcePortrait){
return UIInterfaceOrientationMaskPortrait;
}
return UIInterfaceOrientationMaskPortrait;
}
@interface YNCNavigationViewController : UINavigationController
//旋转方向 默认竖屏
@property (nonatomic , assign) UIInterfaceOrientation interfaceOrientation;
@property (nonatomic , assign) UIInterfaceOrientationMask interfaceOrientationMask;
@end
.m
#pragma mark - 由子控制器控制自己的转屏逻辑
- (BOOL)shouldAutorotate {
return YES;
}
- (UIInterfaceOrientationMask)supportedInterfaceOrientations {
return self.interfaceOrientationMask;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
return self.interfaceOrientation;
}
- (BOOL)shouldAutorotate {
return NO;
}
- (UIInterfaceOrientationMask)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskAll;
}
后面解决方法:
- (void)fullScreenClick:(UIButton *)sender {
sender.selected = !sender.selected;
if (sender.isSelected) {
_backButton.hidden = YES;
[self forceOrientationLandscapeLeft];
} else {
_backButton.hidden = NO;
[self forceOrientationPortrait];
}
}
//MARK: -- 强制横屏
- (void)forceOrientationLandscapeLeft
{
AppDelegate *appdelegate=(AppDelegate *)[UIApplication sharedApplication].delegate;
appdelegate.isForcePortrait=NO;
appdelegate.isForceLandscape=YES;
[appdelegate application:[UIApplication sharedApplication] supportedInterfaceOrientationsForWindow:self.view.window];
YNCNavigationViewController *navi = (YNCNavigationViewController *)self.navigationController;
navi.interfaceOrientation = UIInterfaceOrientationMaskLandscape;
navi.interfaceOrientationMask = UIInterfaceOrientationMaskLandscape;
//设置屏幕的转向为横屏
[[UIDevice currentDevice] setValue:@(UIDeviceOrientationLandscapeLeft) forKey:@"orientation"];
//刷新
[UIViewController attemptRotationToDeviceOrientation];
}
//MARK: -- 强制竖屏
- (void)forceOrientationPortrait
{
AppDelegate *appdelegate=(AppDelegate *)[UIApplication sharedApplication].delegate;
appdelegate.isForcePortrait=YES;
appdelegate.isForceLandscape=NO;
[appdelegate application:[UIApplication sharedApplication] supportedInterfaceOrientationsForWindow:self.view.window];
YNCNavigationViewController *navi = (YNCNavigationViewController *)self.navigationController;
navi.interfaceOrientation = UIInterfaceOrientationPortrait;
navi.interfaceOrientationMask = UIInterfaceOrientationMaskPortrait;
//设置屏幕的转向为竖屏
[[UIDevice currentDevice] setValue:@(UIDeviceOrientationPortrait) forKey:@"orientation"];
//刷新
[UIViewController attemptRotationToDeviceOrientation];
}
#import <UIKit/UIKit.h>
@interface AppDelegate : UIResponder <UIApplicationDelegate>
@property (strong, nonatomic) UIWindow *window;
@property (assign , nonatomic) BOOL isForceLandscape;
@property (assign , nonatomic) BOOL isForcePortrait;
@end
AppDelegate.m
-(UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window{
if (self.isForceLandscape) {
return UIInterfaceOrientationMaskLandscape;
}else if (self.isForcePortrait){
return UIInterfaceOrientationMaskPortrait;
}
return UIInterfaceOrientationMaskPortrait;
}
@interface YNCNavigationViewController : UINavigationController
//旋转方向 默认竖屏
@property (nonatomic , assign) UIInterfaceOrientation interfaceOrientation;
@property (nonatomic , assign) UIInterfaceOrientationMask interfaceOrientationMask;
@end
.m
#pragma mark - 由子控制器控制自己的转屏逻辑
- (BOOL)shouldAutorotate {
return YES;
}
- (UIInterfaceOrientationMask)supportedInterfaceOrientations {
return self.interfaceOrientationMask;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
return self.interfaceOrientation;
}
相关文章推荐
- ios 只让播放视频的 时候能够全屏横屏 其他全部非全屏非横屏 目前已经测试很多 可以
- ios开发 只让播放视频的 时候能够全屏横屏 其他全部非全屏非横屏
- 关于iOS只在视频全屏播放下允许横屏的解决方法
- 实现iOS全局禁止横屏,但kxmovie全屏横屏播放视频
- iOS UIWebView 全屏播放视频, 需横屏,单app不支持横屏, 解决办法
- iOS 全局禁止横屏,但UIWebView 全屏横屏播放视频的解决办法
- iOS 全局禁止横屏,但UIWebView 全屏播放视频,横屏,解决办法
- iOS UIWebView 全屏播放视频横屏 app其他页面不支持横屏
- iOS 全局禁止横屏,但UIWebView 全屏播放视频,横屏,解决办法
- iOS UIWebView 全屏播放视频, 需横屏,单app不支持横屏, 解决办法
- iOS 全局禁止横屏,但UIWebView 全屏播放视频,横屏,解决办法(任意页面横竖屏或禁止)
- iOS 单页UIWebView播放视频,需要横屏
- 【转】 iOS播放视频时候,忽略设备静音按钮
- 全屏录制播放控件--Android 开发中关于视频录制和播放的诸多问题处理
- iOS屏幕旋转之为横屏视频播放增加竖屏模式
- 解决video.js 在 IOS播放的时候自动全屏的问题
- iOS 全局禁止横屏,但视频播放界面选择性横屏的解决办法
- (ios)MPMoviePlayerController首次播放视频的时候,没有控制条
- 使用webview播放视频,全屏状态下适应横屏播放
- Android VideoView播放 项目中的 视频文件 自动横屏 全屏播放