从 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 保持横向大小)。
谢谢你的帮助