我在训练方向和电影播放器。其功能如下:
现在的问题是,在设备旋转到横向模式时,它会进入全屏模式。
,但在返回时,UI并没有正确地转换为纵向模式。
这个问题只与iOS 8.1,8.2有关。它在iOS 7.*和8.3,8.4.中运行良好。
请看附加的屏幕:
全屏前的:

全屏后的:

回到纵向模式:

我使用了这个代码来处理定向:
allowRotation是在AppDelegate.h文件中声明的布尔属性。
//在App中添加电影播放器定向事件的观察者
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayerWillEnterFullscreenNotification:) name:MPMoviePlayerWillEnterFullscreenNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayerWillExitFullscreenNotification:) name:MPMoviePlayerWillExitFullscreenNotification object:nil];//观察员方法
- (void) moviePlayerWillEnterFullscreenNotification:(NSNotification*)notification {
allowRotation = YES;
}
- (void) moviePlayerWillExitFullscreenNotification:(NSNotification*)notification {
allowRotation = NO;
}
-(NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window{
if (([[self.window.rootViewController presentedViewController] isKindOfClass:[MPMoviePlayerViewController class]] && ![[self.window.rootViewController presentedViewController] isBeingDismissed]) || allowRotation)
{
return UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight;
}
else{
allowRotation= NO;
return UIInterfaceOrientationMaskPortrait;
}
return UIInterfaceOrientationMaskPortrait;
}请帮我解决这个问题。
发布于 2015-09-01 19:04:49
做
在您的UIViewController中,实现
-(UIInterfaceOrientationMask)supportedInterfaceOrientations
{
// Do the dynamic logic here
}别
不要忽略传入的window参数:
- (UIInterfaceOrientationMask)application:(UIApplication *)application
supportedInterfaceOrientationsForWindow:(nullable UIWindow *)window您的当前代码实际上没有回答以下问题: ForWindow。
一般的做法是返回
supportedInterfaceOrientationsForWindow中的所有可能的方向supportedInterfaceOrientations中。示例
// App delegate
- (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(nullable UIWindow *)window {
return UIInterfaceOrientationMaskAllButUpsideDown;
}
// View controller
-(UIInterfaceOrientationMask)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskLandscape;
}https://stackoverflow.com/questions/32331889
复制相似问题