问题
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"
回答1:
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.
回答2:
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
来源:https://stackoverflow.com/questions/3229809/system-ignore-iphone-rotation