系统忽略iPhone旋转

发布于 2024-09-09 06:24:19 字数 1288 浏览 6 评论 0原文

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

我乃一代侩神 2024-09-16 06:24:20

在您呈现的视图中,实现 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.

小糖芽 2024-09-16 06:24:20

也许你可以像这样子类化 MPMoviePlayerViewController

// NotRotatingMoviePlayerViewController.h
@interface NotRotatingMoviePlayerViewController : MPMoviePlayerViewController {
}

@end

// NotRotatingMoviePlayerViewController.m
@implementation

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
  return (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft);
}

@end

Maybe you could subclass the MPMoviePlayerViewController like this

// NotRotatingMoviePlayerViewController.h
@interface NotRotatingMoviePlayerViewController : MPMoviePlayerViewController {
}

@end

// NotRotatingMoviePlayerViewController.m
@implementation

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
  return (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft);
}

@end
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文