gpt4 book ai didi

iPhone 在视频播放后强制方向

转载 作者:行者123 更新时间:2023-11-29 05:02:02 26 4
gpt4 key购买 nike

我遇到了一个困扰我的问题,应该很容易解决。这是我的代码:

-(IBAction)playMovie:(id)sender{

NSString *filepath = [[NSBundle mainBundle] pathForResource:@"myMovie" ofType:@"MOV"];
NSURL *fileURL = [NSURL fileURLWithPath:filepath];
moviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:fileURL];

[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(moviePlaybackComplete:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:moviePlayerController];

[self.view addSubview:moviePlayerController.view];
//[moviePlayerController setOrientation:UIInterfaceOrientationLandscapeLeft];
moviePlayerController.fullscreen = YES;
moviePlayerController.scalingMode = MPMovieScalingModeFill;

[moviePlayerController play];

}

- (void)moviePlaybackComplete:(NSNotification *)notification
{

[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait];

moviePlayerController = [notification object];
[[NSNotificationCenter defaultCenter] removeObserver:self
name:MPMoviePlayerPlaybackDidFinishNotification
object:moviePlayerController];

[moviePlayerController.view removeFromSuperview];
[moviePlayerController release];
}

方向:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{
if(UIInterfaceOrientationIsPortrait(toInterfaceOrientation)) {
return(YES);
}

if(UIInterfaceOrientationIsLandscape(toInterfaceOrientation)) {
return([moviePlayerController isFullscreen]);
}




return(NO);

}

一开始这会按预期工作。方向最初强制为纵向,然后播放电影,横向允许电影旋转并以横向方式观看。然后单击完成后,电影结束,界面将保持横向。我需要将其强制返回纵向模式...我见过类似的解决方案

[[UIDevice currentDevice] setOrientation:UIInterfaceOrientationPortrait];

现在似乎从 ios 4.0 开始已弃用

理想情况下,一旦电影完成方法触发,它应该自动旋转到纵向!

有什么解决办法吗?

最佳答案

试试这个:

[[NSNotificationCenter defaultCenter] addObserver:self  
selector:@selector(moviePlaybackComplete:)
name:MPMoviePlayerWillExitFullscreenNotification
object:moviePlayerController];

关于iPhone 在视频播放后强制方向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6708699/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com