我有一个视图控制器,我通过一个嵌入到导航控件的表视图控制器访问。我希望我的视图控制器始终处于纵向方向。视图控制器有一个按钮,用于启动我希望能够自动旋转或始终处于横向状态的视频。
以下代码在没有tableview控制器的情况下工作,但是当我放入tableview时,它会停止工作。
提前感谢任何帮助。
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)play:(id)sender {
NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle]
pathForResource:@"FINAL_De_Air_Purge_System" ofType:@"mp4"]];
MPMoviePlayerViewController *playercontroller = [[MPMoviePlayerViewController alloc]
initWithContentURL:url];
[self presentMoviePlayerViewControllerAnimated:playercontroller];
playercontroller.moviePlayer.movieSourceType = MPMovieSourceTypeFile;
[playercontroller.moviePlayer play];
playercontroller = nil;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
return UIInterfaceOrientationPortrait;
}
- (BOOL)shouldAutorotate {
return NO;
}
@end
答案 0 :(得分:0)
我相信如果你遵循以下规则,你应该做得很好:
-(NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
return UIInterfaceOrientationMaskAllButUpsideDown;
}
应该在App委托
`- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskLandscape;
}`
应该在所有ViewControllers中你不想旋转
- (BOOL)shouldAutorotate
{
return YES;
}
应该在你的ViewController中推动电影播放器让iOS知道它允许旋转
一旦你推动电影播放器,它应该知道它可以旋转,应该工作得很好。当弹出/关闭电影播放器时,应该按照想要旋转前一个viewController。