MPInlineVideoFullscreenViewController在iPhone 6/iOS 8中与UIWebView的旋转
我有一个非常简单的应用程序。它读取XML提要并显示内容。有时,内容会随YouTube视频一起提供。因此,我在AppDelegate中添加了以下内容MPInlineVideoFullscreenViewController在iPhone 6/iOS 8中与UIWebView的旋转,ios,objective-c,iphone,uiwebview,rotation,Ios,Objective C,Iphone,Uiwebview,Rotation,我有一个非常简单的应用程序。它读取XML提要并显示内容。有时,内容会随YouTube视频一起提供。因此,我在AppDelegate中添加了以下内容 - (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window { id presentedViewController = [window.rootViewController pre
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {
id presentedViewController = [window.rootViewController presentedViewController];
NSString *className = presentedViewController ? NSStringFromClass([presentedViewController class]) : nil;
if (window && [className isEqualToString:@"MPInlineVideoFullscreenViewController"]) {
return UIInterfaceOrientationMaskAll;
} else {
return UIInterfaceOrientationMaskPortrait;
}
}
在[_windowsetRootViewController:rootTabBarController]之后;在didFinishLaunchingWithOptions中。它工作得非常好。该应用程序始终锁定纵向,并且仅在播放视频时允许水平查看
我现在正在用iPhone 6/Plus支持将我的应用升级到iOS 8。我已经创建了一个启动屏幕xib来实现这一点。一切都很好。该应用程序在iPhone6/Plus中看起来非常清晰,不再升级
但是,上面的旋转代码不再有效。有什么建议吗?谢谢。在iOS8下,您必须检查AVFullScreenViewController而不是MPInlineVideoFullscreenViewController 例如:
static NSString * const VIDEO_CONTROLLER_CLASS_NAME_IOS7 = @"MPInlineVideoFullscreenViewController";
static NSString * const VIDEO_CONTROLLER_CLASS_NAME_IOS8 = @"AVFullScreenViewController";
- (UIInterfaceOrientationMask)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;
}
}
处理MPMoviePlayerController定向支持的一种更为简洁的方法是在AppDelegate中添加MPMoviePlayer通知的观察者MPMoviePlayerWillerInterFullScreenNotification和MPMoviePlayerWillerExitFullScreenNotification。每当收到通知时,在进入全屏时将allowOrientation标志设置为YES,在退出全屏时将其设置为NO。由于这些通知是在系统调用SupportedInterfaceOrientionsForWindow之前收到的,因此allowOrientation标志可在SupportedInterfaceOrientionsForWindow函数中用于设置适当的方向
IMPLEMENTATION:
@interface AppDelegate ()
@property(assign) BOOL allowOrientationChange;
@end
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
self.allowOrientationChange = NO;
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(setAllowOrientationChangeFlagToYES:)
name:MPMoviePlayerWillEnterFullscreenNotification
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(setAllowOrientationChangeFlagToNO:)
name:MPMoviePlayerWillExitFullscreenNotification
object:nil];
return YES;
}
-(void)setAllowOrientationChangeFlagToYES:(NSNotification*)aNotification{
self.allowOrientationChange = YES;
}
-(void)setAllowOrientationChangeFlagToNO:(NSNotification*)aNotification{
self.allowOrientationChange = NO;
}
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window{
if (self.allowOrientationChange) {
return UIInterfaceOrientationMaskAllButUpsideDown;
}
else{
return UIInterfaceOrientationMaskPortrait;
}
}
是的,您必须返回正确类型的UIInterfaceOrientationMaskinstead,即nsInteger。我相应地更新了代码片段。