【问题标题】:iOS - UI is not transforming with device rotation changeiOS - UI 不随设备旋转变化而变化
【发布时间】:2015-09-01 12:38:56
【问题描述】:

我正在研究方向和电影播放器​​。功能如下:

  • 如果我打开 MPMoviePlayer 的全屏模式,那么它应该只以横向模式打开。

  • 如果我将设备旋转到横向,它将自动启动 MPMoviePlayer 的全屏模式

  • 当我关闭它时,它应该再次回到纵向模式
    MPMoviePlayer 的全屏模式或将设备旋转到纵向模式。

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

但是在回来的时候,UI 没有正确转换为纵向模式。

此问题仅适用于 iOS 8.1、8.2。它在 iOS 7.* 和 8.3、8.4 中运行良好。

请查看附加屏幕:

全屏前:

全屏后:

回到纵向模式:

我已使用此代码来处理方向:

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

//在App Delegate中为电影播放器​​方向事件添加观察者

[[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;
}

请帮我解决这个问题。

【问题讨论】:

  • 你是怎么解决的?

标签: ios iphone orientation mpmovieplayercontroller uiinterfaceorientation


【解决方案1】:

在你的UIViewController 中,实现

-(UIInterfaceOrientationMask)supportedInterfaceOrientations
{
    // Do the dynamic logic here
}

不要

不要忽略传入的window参数:

- (UIInterfaceOrientationMask)application:(UIApplication *)application
      supportedInterfaceOrientationsForWindow:(nullable UIWindow *)window

您当前的代码实际上没有响应问题:ForWindow.


一般的做法是返回

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

示例

// App delegate
- (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(nullable UIWindow *)window {
    return UIInterfaceOrientationMaskAllButUpsideDown;
}

// View controller
-(UIInterfaceOrientationMask)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskLandscape;
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-06-15
    • 1970-01-01
    • 1970-01-01
    • 2012-11-26
    • 2015-10-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多