4

我在浏览器中嵌入了一个 Youtube 视频,它是全肖像应用程序的一部分。当您启动 youtube 视频时,它会在 MPAVController 中播放,并且允许横向旋转。这对我来说不是问题,但问题是如果视频是横向的,我按“确定”关闭视频;我返回浏览器,但 iPhone 状态栏现在卡在横向模式,在应用程序顶部留下一个空白区域,并且状态栏根据旋转方向与我的应用程序的右侧或左侧部分重叠。

我的包含 UIWebView 的视图控制器被锁定为纵向:

- (BOOL) shouldAutorotate
{
    return YES;
}

- (NSUInteger)supportedInterfaceOrientations{
    return UIInterfaceOrientationMaskPortrait;
}

请注意,使用 6.0 之前的 SDK 进行编译时不会出现此问题。

有类似问题的任何人都有解决方案吗?

4

2 回答 2

5

我面临同样的问题。这是我解决它的方法:

首先在持有 UIWebView 的 ViewController 上注册接收 ExitFullscreenNotification:

- (void)viewDidLoad {
    [super viewDidLoad];
    // For FullSCreen Exit
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(youTubeVideoExit:) 
                                                 name:@"UIMoviePlayerControllerDidExitFullscreenNotification"
                                               object:nil];
}

然后,在“退出全屏”处理程序上,强制纵向模式:

- (void)youTubeVideoExit:(id)sender {
  [[UIApplication sharedApplication] setStatusBarOrientation:UIDeviceOrientationPortrait animated:NO];
}

当视频以横向模式结束时,用户会看到状态栏在一瞬间改变其位置。这可能不是最好的解决方案,但至少解决了问题。

希望能帮助到你!

于 2012-10-25T16:00:16.037 回答
0

事实证明我的视图嵌入在 UINavigationController 中,所以我需要在那里处理我的旋转。

我创建了一个类别并将我的轮换代码放在那里

UINavigationController+Autorotate.m

#import "UINavigationController+Autorotate.h"

@implementation UINavigationController (Autorotate)

- (NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskPortrait;
}

@end

UINavigationController+Autorotate.h

#import <UIKit/UIKit.h>

@interface UINavigationController (Autorotate)

- (NSUInteger)supportedInterfaceOrientations;

@end
于 2012-10-10T14:49:29.173 回答