我正在开发一个xcode的新应用程序,该应用程序是纵向视图,但视频应该能够在纵向和横向视图中 . 我编写了这段代码,但它不能100%工作
AppDelegate.h
#import <MediaPlayer/MediaPlayer.h>
@property (strong, nonatomic) MPMoviePlayerViewController *VideoPlayer;
AppDelegate.m
@synthesize VideoPlayer;
- (NSUInteger)application:(UIApplication *)application
supportedInterfaceOrientationsForWindow:(UIWindow *)window {
if ([[self.window.rootViewController presentedViewController]
isKindOfClass:[MPMoviePlayerViewController class]]) {
return UIInterfaceOrientationMaskAllButUpsideDown;
} else {
if ([[self.window.rootViewController presentedViewController]
isKindOfClass:[UINavigationController class]]) {
// look for it inside UINavigationController
UINavigationController *nc = (UINavigationController *)[self.window.rootViewController presentedViewController];
// is at the top?
if ([nc.topViewController isKindOfClass:[MPMoviePlayerViewController class]]) {
return UIInterfaceOrientationMaskAllButUpsideDown;
// or it's presented from the top?
} else if ([[nc.topViewController presentedViewController]
isKindOfClass:[MPMoviePlayerViewController class]]) {
return UIInterfaceOrientationMaskAllButUpsideDown;
}
}
}
return UIInterfaceOrientationMaskPortrait;
}
此代码的问题是,如果用户在横向模式下观看视频时关闭视频播放器,即使我在Xcode GUI中禁用了视频播放器,如果用户旋转设备关闭视频播放器(app在横向视图中)为肖像它切换到纵向视图,然后它保持纵向(无论设备旋转) . 即使用户在横向模式下观看视频时关闭视频播放器,如何才能将该应用切换为纵向视图?
谢谢!
2 回答
经过长时间的研究,我终于找到了解决方案 .
1)启用应用程序的所有方向 .
2)对您的根导航控制器进行子类化,并实现这两种方法
3)MPMoviePlayerViewController的子类
4)现在你应该呈现子类MoviePlayerController,所有的东西应该工作!
你几乎通过在AppDelegate中添加该功能来实现它 . 唯一的问题是,当用户从横向视频回来时,该应用程序将成为视频 . 解决方案就在这里:
这里的关键是仔细检查呈现的视图控制器是否正在解除(退出) .