首页 文章

MPMoviePlayerController重定向纵向到横向和回到纵向(iOS 4.1)

提问于
浏览
25

从iOS 3.2开始,MPMoviePlayerController类允许在视图层次结构中嵌入电影 . 现在我面临这个问题:我通过放置一个MPMoviePlayerController实例来创建我的肖像视图 . 当用户触摸“全屏”按钮时,此视图以全屏模式进入,但视图仍保持纵向 . 当用户旋转设备时,全屏影片视图不会自动旋转,因为我的应用禁止横向界面方向 . 因此,为了允许电影播放器全屏视图的自动旋转,我更改了我的视图控制器shouldAutorotateToInterfaceOrientation:方法,如果 - 并且仅当 - 电影播放器处于全屏模式时返回YES . 这非常有效:当用户全屏进入然后旋转到横向时,播放器会自动旋转到横向并填充整个屏幕 .

// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
    //return (interfaceOrientation == UIInterfaceOrientationPortrait);
    if(UIInterfaceOrientationIsPortrait(interfaceOrientation)) {
        return(YES);
    }

    if(UIInterfaceOrientationIsLandscape(interfaceOrientation)) {
        return([movieController isFullscreen]);
    }

return(NO);
}

现在,当我在全景视图中触摸“完成”按钮同时保持横向状态时,会出现问题 . 完整的屏幕关闭,然后我看到的是我的原始视图自动旋转:但我不希望这种自动旋转 .

部分但不可接受的解决方案是侦听“MPMoviePlayerDidExitFullscreenNotification”,如果界面旋转为横向,则强制重定向以使用未记录的私有函数:

[[UIDevice currentDevice] setOrientation:UIDeviceOrientationPortrait]

这有效但不可接受,因为禁止使用此方法 .

我尝试使用 [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait] 强制定位但是因为我工作(UITabBar仍然是横向大小) .

谢谢你的帮助

2 回答

相关问题