找到了。
有同样的问题 - 这就是我所做的。我建议将代码一一添加到您的项目中,以确切了解它是如何工作的。
首先 - 我把东西是纵向模式。
[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait animated:NO];
然后我把电影推到状态栏上。注意 - 这假设视频具有 4x3 纵横比
theVideo = [[MPMoviePlayerController alloc] initWithContentURL: [NSURL fileURLWithPath : path]];
float aspectRatio = (3.0f/4.0f);
float theMovieHeight = [self view].bounds.size.width * aspectRatio;
[[theVideo view] setFrame:(CGRectMake(0, [self view].bounds.size.height - theMovieHeight, [self view].bounds.size.width, theMovieHeight ))];
然后,在应用程序启动的地方(在我的项目中,它在didFinishLaunchingWithOptions
函数中)——无论如何,您只需要访问窗口对象即可。
float aspectRatio = (3.0f/4.0f);
float theMovieHeight = self.window.bounds.size.width * aspectRatio;
float theSpaceAboveTheMovie = self.window.bounds.size.height - theMovieHeight;
float whereTheMovieShouldBeCentered = (self.window.bounds.size.height - theMovieHeight) / 2;
CGAffineTransform theTransform = CGAffineTransformMakeTranslation(0,0);
theTransform = CGAffineTransformScale(theTransform, 1.0f/aspectRatio, 1.0f/aspectRatio);
theTransform = CGAffineTransformTranslate(theTransform, -whereTheMovieShouldBeCentered, 0);
theTransform = CGAffineTransformRotate(theTransform, M_PI / 2);
theTransform = CGAffineTransformTranslate(theTransform, 0, -theSpaceAboveTheMovie);
[self.window setTransform:theTransform];
请记住,仿射变换是以相反的顺序完成的。因此,如果您想查看每个转换在做什么(我建议您应该这样做),请注释掉前三个
在这里,您应该会看到以页面为中心的电影和状态栏
// theTransform = CGAffineTransformScale(theTransform, 1.0f/aspectRatio, 1.0f/aspectRatio);
// theTransform = CGAffineTransformTranslate(theTransform, -whereTheMovieShouldBeCentered, 0);
// theTransform = CGAffineTransformRotate(theTransform, M_PI / 2);
theTransform = CGAffineTransformTranslate(theTransform, 0, -theSpaceAboveTheMovie);
然后前两个
在这里你应该看到电影和状态栏旋转并且不再居中
// theTransform = CGAffineTransformScale(theTransform, 1.0f/aspectRatio, 1.0f/aspectRatio);
// theTransform = CGAffineTransformTranslate(theTransform, -whereTheMovieShouldBeCentered, 0);
theTransform = CGAffineTransformRotate(theTransform, M_PI / 2);
theTransform = CGAffineTransformTranslate(theTransform, 0, -theSpaceAboveTheMovie);
在这里你应该看到它旋转并居中
// theTransform = CGAffineTransformScale(theTransform, 1.0f/aspectRatio, 1.0f/aspectRatio);
theTransform = CGAffineTransformTranslate(theTransform, -whereTheMovieShouldBeCentered, 0);
theTransform = CGAffineTransformRotate(theTransform, M_PI / 2);
theTransform = CGAffineTransformTranslate(theTransform, 0, -theSpaceAboveTheMovie);
和他们一起,它被旋转和全屏
你可以在这里下载我的示例代码。