在iPad应用程序的方向问题
我正在创建一个应用程序,我可以通过它播放mpmovieplayer控制器所做的视频。现在,我需要为这两种方向执行此操作。但帧没有正确设置。在iPad应用程序的方向问题
其代码follws
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
[super viewDidLoad];
[self shouldAutorotateToInterfaceOrientation:[UIDevice currentDevice].orientation];
NSURL *temp = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"Floating" ofType:@"mp4"]];
mpviewController = [[MPMoviePlayerViewController alloc] initWithContentURL:temp];
mpviewController.view.frame = CGRectMake(0, 0, 768, 1024);
mpviewController.view.backgroundColor = [UIColor clearColor];
mpviewController.moviePlayer.movieSourceType = MPMovieSourceTypeFile;
mpviewController.view.userInteractionEnabled= NO;
mpviewController.moviePlayer.fullscreen= YES;
mpviewController.moviePlayer.controlStyle = MPMovieControlStyleNone;
[[mpviewController moviePlayer] play];
[self.view addSubview:mpviewController.view];
}
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
currentOrientation = interfaceOrientation;
//[self SetInterface];
if(interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)
mpviewController.view.frame = CGRectMake(0, 0, 768, 1024);
else if(interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight)
mpviewController.view.frame = CGRectMake(0, 0, 1024, 768);
return YES;
}
我不知道我在哪里wrong.Please让我知道任何chages在代码中做出。为了得到正确的方向。
Ragards ABHI
首先 我相信你并不需要调整mpviewController,因为它会单独调整它的自我。 你应该只设置 -
二
在shouldAutorotateToInterfaceOrientation只设置了支持的方向在shouldAutorotateToInterfaceOrientation。
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return YES;
}
如果剂量不这样做,你改变视图属性中 -
-(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration{
if (UIInterfaceOrientationIsPortrait(interfaceOrientation)){
//do what you want for portrait
}else{
//do what you want for landscape
}
}
只*不*使用私人方法做到这一点:setOrientation:UIDeviceOrientationPortrait动画:否 –
不,我是stil面临同样的问题,如果你可以提供代码snipet它会很棒。 –
你应该只返回YES或NO在shouldAutorotateToInterfaceOrientation:
方法,它是由框架调用只拿到你的控制器对所支持的方向的信息,请阅读同苹果文档。
你需要的方向改变注册notifictaion
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientationChanged:) name:@"UIDeviceOrientationDidChangeNotification" object:nil];
实现您的orientationChanged:
方法。
//********** ORIENTATION CHANGED **********
- (void) orientationChanged:(NSNotification *)note
{
NSLog(@"Orientation has changed: %d", [[note object] orientation]);
//Put your code here from shouldAutorotateToInterfaceOrientation:
}
不要忘记将其删除。
[[NSNotificationCenter defaultCenter] removeObserver:self];
这里有一些链接
这将是伟大的,如果你可以提供一些代码片段,因为我试过,但结果是相同的,即使我通过链接你建议。只要使代码中的chages我提出的问题,并张贴在你的asnwer这将是很大的帮助因为我在这一点上很困难。 –
确实完成thnaks的链接,真的有帮助.. –
无需更改任何值编码..简单的插入下面的值编码到应用程序,它会自动检测取向...
UINavigationBar * bar = [self.navigationController navigationBar];
[bar setTintColor:[UIColor blackColor]]; NSBundle * bundle = [NSBundle mainBundle];
NSString * moviePath = [bundle pathForResource:@“sharkdivertrailer”ofType:@“mp4”];
NSURL * movieURL = [[NSURL fileURLWithPath:moviePath] retain];
MPMoviePlayerController * theMovie = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];
theMovie.view。frame = CGRectMake(184,200,400,300); [theMovie play];
MPMoviePlayerViewController * moviePlayer = [[MPMoviePlayerViewController alloc] initWithContentURL:movieURL];
[self presentMoviePlayerViewControllerAnimated:moviePlayer];
@luzhin感谢编辑问题,实际上我不知道如何添加我们的代码与问题,这就是为什么发生这种情况。 –
没问题,你可以使用这些HTML标签'
'在你的问题中添加代码 – insumity@luzin谢谢你将在下一个问题中做到这一点。 –