简体   繁体   English

iOS-UI不会随着设备旋转的改变而变化

[英]iOS - UI is not transforming with device rotation change

I am working on orientation and Movie Player. 我正在研究方向和电影播放器​​。 The functionality is as follows: 功能如下:

  • If I turn on full screen mode of MPMoviePlayer then it should open in landscape mode only. 如果我打开MPMoviePlayer的全屏模式,则它应仅在横向模式下打开。

  • If I rotate my device to landscape, then it will automatically starts full screen mode of MPMoviePlayer 如果我将设备旋转到横向,则它将自动启动MPMoviePlayer的全屏模式

  • And again it should come back to portrait mode when I turn off 当我关闭电源后,它应该又回到人像模式
    fullscreen mode of MPMoviePlayer or rotate device to portrait mode. MPMoviePlayer的全屏模式或将设备旋转到纵向模式。

Now Problem is that, it goes to full screen mode on device rotation to landscape mode 现在的问题是,当设备旋转到横向模式时,它将进入全屏模式

but at the time of come back, The UI is not transforming to portrait mode properly. 但是在返回时,UI无法正确转换为纵向模式。

This Problem is only with iOS 8.1, 8.2. 此问题仅适用于iOS 8.1、8.2。 It is working fine in iOS 7.* and 8.3, 8.4. 在iOS 7. *和8.3、8.4中运行正常。

Please look at attached screens: 请查看所附的屏幕:

Before Full screen: 全屏之前:

在此处输入图片说明

After full screen: 全屏显示后:

在此处输入图片说明

Come back to portrait mode: 返回肖像模式:

在此处输入图片说明

I have used this code to handle orientation: 我已经使用此代码来处理方向:

allowRotation is Boolean property declared in AppDelegate.h file allowRotation是在AppDelegate.h文件中声明的布尔属性

//Adding observer for movie player orientation event In App Delegate //在App Delegate中为电影播放器​​定向事件添加观察者

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayerWillEnterFullscreenNotification:) name:MPMoviePlayerWillEnterFullscreenNotification object:nil];

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

// Observer methods //观察者方法

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

Please help me to resolve this problem. 请帮助我解决此问题。

Do

In your UIViewController , implement 在您的UIViewController ,实现

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

Don't

Do not ignore the window parameter passed in: 不要忽略传入的window参数:

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

Your current code is actually not responding to the question: ForWindow. 您当前的代码实际上没有响应以下问题:ForWindow。


The general practice is to return 一般做法是返回

  1. all the possible orientations for a given window (you typically only have a single window per application) in supportedInterfaceOrientationsForWindow 给定窗口(在每个应用程序中通常只有一个窗口)在supportedInterfaceOrientationsForWindow 所有可能方向
  2. a subset of that list, which can be dynamic, in the view controller supportedInterfaceOrientations . 在视图控制器supportedInterfaceOrientations ,该列表的子集可以是动态的。

Example

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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM