MPMovieplayer中有关于景观问题的问题太多了。我的应用程序是纵向模式。但我想在横向模式下观看视频。我已经拥有视频的横向/纵向功能。我使用以下代码:
static NSString * const VIDEO_CONTROLLER_CLASS_NAME_IOS7 = @"MPInlineVideoFullscreenViewController";
static NSString * const VIDEO_CONTROLLER_CLASS_NAME_IOS8 = @"AVFullScreenViewController";
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
if ([[window.rootViewController presentedViewController] isKindOfClass:NSClassFromString(VIDEO_CONTROLLER_CLASS_NAME_IOS7)] ||
[[window.rootViewController presentedViewController] isKindOfClass:NSClassFromString(VIDEO_CONTROLLER_CLASS_NAME_IOS8)])
{
return UIInterfaceOrientationMaskAllButUpsideDown;
}
else {
return UIInterfaceOrientationMaskPortrait;
}
}
该代码在iOS 7和iOS8中都运行良好。 但问题是,当设备处于横向模式时,视频首先以纵向模式打开。方向改变后应用程序工作正常。
提前致谢。
答案 0 :(得分:2)
经过漫长的R& D和不同的方法,花了2-3天。最后我在朋友的帮助下得到了答案。如果我们的视图控制器处于纵向模式,则以下代码无法推送播放器在景观视图中查看。
static NSString * const VIDEO_CONTROLLER_CLASS_NAME_IOS7 = @"MPInlineVideoFullscreenViewController";
static NSString * const VIDEO_CONTROLLER_CLASS_NAME_IOS8 = @"AVFullScreenViewController";
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
if ([[window.rootViewController presentedViewController] isKindOfClass:NSClassFromString(VIDEO_CONTROLLER_CLASS_NAME_IOS7)] ||
[[window.rootViewController presentedViewController] isKindOfClass:NSClassFromString(VIDEO_CONTROLLER_CLASS_NAME_IOS8)])
{
return UIInterfaceOrientationMaskAllButUpsideDown;
}
else {
return UIInterfaceOrientationMaskPortrait;
}
在我的情况下问题是我的UIWebView容器视图控制器非常时间处于纵向模式。我不知道在UINavigationController中推送ViewController之后是否为该ViewController调用了方向方法。
-(BOOL)shouldAutorotate;
-(NSUInteger)supportedInterfaceOrientations;
要解决此问题,我将在ViewDidLoad方法
中添加以下代码NSNumber *value = [NSNumber numberWithInt:UIInterfaceOrientationLandscapeLeft];
[[UIDevice currentDevice] setValue:value forKey:@"orientation"];
并在viewWillDisappear中跟随代码
NSNumber *value = [NSNumber numberWithInt:UIInterfaceOrientationPortrait];
[[UIDevice currentDevice] setValue:value forKey:@"orientation"];
上面的代码最终解决了我的问题。
感谢所有支持我解决这个问题的人。