gpt4 book ai didi

iphone - MPMoviePlayerController 将纵向重新定向为横向,然后返回纵向(iOS 4.1)

转载 作者:行者123 更新时间:2023-12-03 18:17:21 25 4
gpt4 key购买 nike

自 iOS 3.2 起,MPMoviePlayerController 类允许在 View 层次结构中嵌入电影。现在我面临这个问题:我通过放置 MPMoviePlayerController 的实例来创建纵向 View 。当用户触摸“全屏”按钮时,该 View 进入全屏模式,但 View 保持纵向。当用户旋转设备时,全屏电影 View 不会自动旋转,因为我的应用程序禁止横向界面方向。因此,为了允许电影播放器​​全屏 View 自动旋转,我更改了 View Controller 的 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);
}

现在,当我在保持横向状态时触摸全屏 View 中的“完成”按钮时,就会出现问题。全屏关闭,然后我看到的是自动旋转的原始 View :但我不想要这种自动旋转。

一个部分但 Not Acceptable 解决方案是监听“MPMoviePlayerDidExitFullscreenNotification”,并且如果界面旋转为横向,则强制重新定向以使用未记录的私有(private)函数:

[[UIDevice currentDevice] setOrientation:UIDeviceOrientationPortrait]

这可行,但 Not Acceptable ,因为禁止使用此方法。

我尝试使用 [[UIApplication shareApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait] 强制方向,但由于我位于选项卡栏中,所以这不起作用(UITabBar 保持横向大小)。

感谢您的帮助

最佳答案

您可以为 MPMovieplayer 使用单独的 View Controller 。您不必覆盖

(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation

在原始 View Controller 中。

如果您使用MPMoviePlayerViewController ,一切都已经为您设置好了,因为方法 shouldAutorotateToInterfaceOrientation: 将默认返回 YES。您可以将其用作 subview 或通过调用
以模态方式呈现它presentMoviePlayerViewControllerAnimated:

关于iphone - MPMoviePlayerController 将纵向重新定向为横向,然后返回纵向(iOS 4.1),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3960665/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com