首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >iOS - UI并没有随着设备旋转的改变而转换。

问iOS - UI并没有随着设备旋转的改变而转换。
EN

Stack Overflow用户
提问于 2015-09-01 12:38:56
回答 1查看 579关注 0票数 0

我在训练方向和电影播放器。其功能如下:

  • 如果我打开MPMoviePlayer的全屏模式,那么它应该只在景观模式下打开。
  • 如果我将我的设备旋转到景致,那么它将自动启动MPMoviePlayer的全屏模式。
  • 再一次,当我关掉它的时候,它应该会回到肖像模式。 MPMoviePlayer全屏模式或将设备旋转为纵向模式。

现在的问题是,在设备旋转到横向模式时,它会进入全屏模式。

,但在返回时,UI并没有正确地转换为纵向模式。

这个问题只与iOS 8.1,8.2有关。它在iOS 7.*和8.3,8.4.中运行良好。

请看附加的屏幕:

全屏前的:

​

​

全屏后的:

​

​

回到纵向模式:

​

​

我使用了这个代码来处理定向:

allowRotation是在AppDelegate.h文件中声明的布尔属性。

//在App中添加电影播放器定向事件的观察者

代码语言:javascript
复制
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayerWillEnterFullscreenNotification:) name:MPMoviePlayerWillEnterFullscreenNotification object:nil];

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayerWillExitFullscreenNotification:) name:MPMoviePlayerWillExitFullscreenNotification object:nil];

//观察员方法

代码语言:javascript
复制
- (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;
}

请帮我解决这个问题。

EN

回答 1

Stack Overflow用户

发布于 2015-09-01 19:04:49

做

在您的UIViewController中,实现

代码语言:javascript
复制
-(UIInterfaceOrientationMask)supportedInterfaceOrientations
{
    // Do the dynamic logic here
}

别

不要忽略传入的window参数:

代码语言:javascript
复制
- (UIInterfaceOrientationMask)application:(UIApplication *)application
      supportedInterfaceOrientationsForWindow:(nullable UIWindow *)window

您的当前代码实际上没有回答以下问题: ForWindow。

一般的做法是返回

  1. 为给定窗口(通常每个应用程序只有一个窗口)在supportedInterfaceOrientationsForWindow中的所有可能的方向
  2. 该列表的一个子集,可以是动态的,在视图控制器supportedInterfaceOrientations中。

示例

代码语言:javascript
复制
// App delegate
- (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(nullable UIWindow *)window {
    return UIInterfaceOrientationMaskAllButUpsideDown;
}

// View controller
-(UIInterfaceOrientationMask)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskLandscape;
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/32331889

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档