vig*_*o24 25 iphone uiinterfaceorientation
从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);
}
Run Code Online (Sandbox Code Playgroud)
现在,当我在全景视图中触摸"完成"按钮的同时保持横向状态时,会出现问题.全屏关闭,然后我看到的是我的原始视图自动旋转:但我不希望这种自动旋转.
部分但不可接受的解决方案是侦听"MPMoviePlayerDidExitFullscreenNotification",如果界面旋转为横向,则强制重定向以使用未记录的私有函数:
[[UIDevice currentDevice] setOrientation:UIDeviceOrientationPortrait]
Run Code Online (Sandbox Code Playgroud)
这有效但不可接受,因为禁止使用此方法.
我试图强制使用方向,[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait]但因为我在Tab栏中这不起作用(UITabBar仍然是横向大小).
谢谢你的帮助
您可以为 MPMovieplayer 使用单独的视图控制器。您不必覆盖
(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
在原始视图控制器中。
如果您使用MPMoviePlayerViewController,一切都已经为您设置好了,因为该方法shouldAutorotateToInterfaceOrientation:默认返回 YES。您可以将其用作子视图或通过调用以模态方式呈现它
presentMoviePlayerViewControllerAnimated:
| 归档时间: |
|
| 查看次数: |
16102 次 |
| 最近记录: |