Mih*_*atu 11 iphone video objective-c rotation uiwebview
所以我对我正在构建的应用程序存在这个问题,我无法弄清楚.我的应用程序具有以下结构:
UITabBarController - > UIViewController - > UIViewController
最后一个视图控制器包含一个UIWebView,它加载整个页面.在该页面中有一部电影(mp4),用户可以在点击大圆形播放按钮后播放.
该应用程序使其以纵向模式运行,并且由于其初始设计,我无法以其他方式运行它.
我想要实现的是让用户在电影开始播放后旋转手机并相应地旋转电影.我通过收听NSNotificationsCenter发送的不同NSNotifications来播放电影时设法"检测".
我用它来检测开始:
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(movieIsPlaying:)
name:@"UIMoviePlayerControllerDidEnterFullscreenNotification"
object:nil];
Run Code Online (Sandbox Code Playgroud)
这用于检测结束:
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(movieStopedPlaying:)
name:@"UIMoviePlayerControllerDidExitFullscreenNotification"
object:nil];
Run Code Online (Sandbox Code Playgroud)
现在使用2个选择器,我将一个全局变量设置为YES或NO,我稍后可以使用它
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
Run Code Online (Sandbox Code Playgroud)
如果我总是从上面的方法返回YES,我的应用程序界面会在everyscreen上旋转,除非电影启动并运行.最奇怪的是:
此外,如果我以纵向模式启动电影,它将永远不会旋转.
所以,如果你能以某种方式帮助我,请各位让我知道.我真的很绝望.如果您需要更多信息,请告诉我.
谢谢!
更新
最后,我为上述两种方法提出了这个解决方案:
- (void)movieIsPlaying:(NSNotification *)notification
{
if (![Globals canRotateInterface]) {
[Globals setCanRotateInterface:YES];
[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight animated:NO];
[[[[notification object] view] window] setBounds:CGRectMake(0, 0, 480, 320)];
[[[[notification object] view] window] setCenter:CGPointMake(160, 240)];
[[[[notification object] view] window] setTransform:CGAffineTransformMakeRotation(M_PI / 2)];
}
}
- (void)movieStopedPlaying:(NSNotification *)notification
{
if ([Globals canRotateInterface]) {
[Globals setCanRotateInterface:NO];
[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait animated:NO];
[[[[notification object] view] window] setBounds:CGRectMake(0, 0, 320, 480)];
[[[[notification object] view] window] setTransform:CGAffineTransformIdentity];
// Little hack to force an orientation rotation so that all elements get their original size and place (eg. Navigation bar)
UINavigationController *dummyNavigationViewController = [[UINavigationController alloc] init];
[self presentModalViewController:dummyNavigationViewController animated:NO];
[self dismissModalViewControllerAnimated:NO];
[dummyNavigationViewController release];
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5570 次 |
| 最近记录: |