System ignore iPhone rotation

為{幸葍}努か 提交于 2019-12-11 04:13:15

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!