系统忽略iPhone旋转
UIApplication 中是否有像 beginIgnoringInteractionEvents 这样的函数忽略旋转而不是触摸?我需要我的应用程序不只在我呈现的 MPMovePlayerViewController
中旋转。
谢谢
[更新]
这是我的代码——
MPMoviePlayerViewController *mpViewController = [[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL URLWithString:videoURL]];
[mpViewController shouldAutorotateToInterfaceOrientation:UIInterfaceOrientationLandscapeRight];
[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight animated:NO];
[self presentMoviePlayerViewControllerAnimated:mpViewController];
[mpViewController release];
我通过添加 shouldAutorotateToInterfaceOrientation: 和 setStatusBarOrientation: 方法使其工作。它在模拟器中工作。但是,如果我在视频播放时旋转 iPhone,状态栏也会旋转并保持“卡在”纵向状态。
我的问题图片位于 http://i28.tinypic.com/357mrub.png
[更新2]
通过子类化MPMoviePlayerViewController(并实现shouldAutorotate方法),程序可以按预期旋转。只有视频无法播放,因为该行
[self presentMoviePlayerViewControllerAnimated:mpViewController];
不接受我的子类。
“警告:不兼容的 Objective-C 类型 'struct NoRotate *',当从不同的 Objective-C 类型传递 'presentMoviePlayerViewControllerAnimated:' 的参数 1 时,预期为 'struct MPMoviePlayerViewController *'”
Is there a function like beginIgnoringInteractionEvents in UIApplication that ignores rotation instead of touches? I need my app NOT to rotate just in an MPMovePlayerViewController
that I present.
Thanks
[UPDATE]
Here's my code --
MPMoviePlayerViewController *mpViewController = [[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL URLWithString:videoURL]];
[mpViewController shouldAutorotateToInterfaceOrientation:UIInterfaceOrientationLandscapeRight];
[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight animated:NO];
[self presentMoviePlayerViewControllerAnimated:mpViewController];
[mpViewController release];
I got it working by adding both the shouldAutorotateToInterfaceOrientation: and setStatusBarOrientation: methods. It works in the simulator. However if I rotate the iPhone while the video is playing, the status bar rotates as well and stays 'stuck' in the portrait orientation.
image of my problem at http://i28.tinypic.com/357mrub.png
[UPDATE 2]
By subclassing MPMoviePlayerViewController (and implementing the shouldAutorotate method), the program rotates as it should. Only the video doesn't play because the line
[self presentMoviePlayerViewControllerAnimated:mpViewController];
doesn't accept my subclass.
"warning: incompatible Objective-C types 'struct NoRotate *', expected 'struct MPMoviePlayerViewController *' when passing argument 1 of 'presentMoviePlayerViewControllerAnimated:' from distinct Objective-C type"
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在您呈现的视图中,实现 shouldAutoRotate 方法并简单地返回“NO”。这将导致手机忽略任何和所有方向变化。
In the view you present, implement the shouldAutoRotate method and simply return "NO". This will cause the phone to ignore any and all orientation changes.
也许你可以像这样子类化 MPMoviePlayerViewController
Maybe you could subclass the MPMoviePlayerViewController like this