【发布时间】:2016-08-14 02:06:27
【问题描述】:
我想以横向模式全屏播放视频。 我的应用程序锁定在纵向模式。 如何实现这一点。请帮我。 提前致谢
【问题讨论】:
标签: ios objective-c landscape uiinterfaceorientation
我想以横向模式全屏播放视频。 我的应用程序锁定在纵向模式。 如何实现这一点。请帮我。 提前致谢
【问题讨论】:
标签: ios objective-c landscape uiinterfaceorientation
NSNumber *value = [NSNumber numberWithInt:UIInterfaceOrientationLandscapeLeft];
[[UIDevice currentDevice] setValue:value forKey:@"orientation"];
只需在呈现的视图控制器的- viewDidAppear: 中调用它即可。
另一种方式:
首先,您必须了解,即使只打开 100 多个横向视图中的一个,您的应用也应该允许横向和纵向界面方向。默认情况下是这种情况,但您可以在目标的设置、常规选项卡、部署信息部分中检查它
然后,因为您允许整个应用程序同时使用横向和纵向,您必须告诉每个仅纵向的UIViewController 它不应该自动旋转,添加此方法的实现:-
- (BOOL)shouldAutorotate {
return NO;
}
最后,对于您的特定横向控制器,并且因为您说您是以模态方式呈现它,您可以实现这些方法:-
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
return UIInterfaceOrientationLandscapeLeft; // or Right of course
}
-(UIInterfaceOrientationMask)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskLandscape;
}
希望这会有所帮助:)
【讨论】:
autorotating 到 videoPlayerViewController 并为该 videoplayerviewcontroller 设置横向横向
我已经在我的应用程序中完成了这项工作。为此,您需要检查要在其中播放视频的视图控制器。
您要做的第一件事是在项目目标中检查设备方向到纵向、横向左侧、横向右侧
在您的 AppDelegate 中执行以下代码
-(NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window{
UIStoryboard *mainStoryboard;
if (IS_IPHONE) {
mainStoryboard= [UIStoryboard storyboardWithName:@"Main" bundle: nil];
}
else{
mainStoryboard= [UIStoryboard storyboardWithName:@"Main_iPad" bundle: nil];
}
ViewControllerThatPlaysVideo *currentViewController= ViewControllerThatPlaysVideo*)[mainStoryboard instantiateViewControllerWithIdentifier:@"postDetailView"];
if(navigationController.visibleViewController isKindOfClass: [ViewControllerThatPlaysVideo class]]){
if([currentViewController playerState])
return UIInterfaceOrientationMaskLandscape|UIInterfaceOrientationMaskPortrait;
return UIInterfaceOrientationMaskPortrait;
}
return UIInterfaceOrientationMaskPortrait;
}
【讨论】:
swift 3 中最简单的解决方案 将此添加到您的应用委托:
func application(_ application: UIApplication, supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask {
if window == self.window {
return .portrait
} else {
return .allButUpsideDown
}
}
【讨论】:
盯着这个页面看了差不多一整天,我终于想出了一个适合所有人的节省工作时间的解决方案,
转到项目导航器,选择您的项目,然后在“一般”中选择设备方向中的 potrait。
还要确保您使用 modal segue 来显示 LandscapeController。
现在将它添加到您想要横向模式的控制器中。
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(true)
}
override var shouldAutorotate: Bool {
return false
}
override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
return .landscapeRight
}
override var preferredInterfaceOrientationForPresentation: UIInterfaceOrientation {
return .landscapeRight
}
就是这样,伙计们。
【讨论】: