我正在创建一个iOS iPad应用程序,除其他外,它在一个屏幕上使用MPMoviePlayerController,在另一个名为“CommandMessageView”的视图下使用。下面是我的.h文件的相关部分:
@interface MovieViewController : UIViewController
@property (strong, nonatomic) MPMoviePlayerController *moviePlayer;
@property (strong, nonatomic) IBOutlet UIView *MovieView;
@property (strong, nonatomic) IBOutlet UIView *CommandMessageView;然后是.m文件的相关部分:
@implementation MovieViewController
@synthesize MovieView;
@synthesize moviePlayer;
@synthesize CommandMessageView;
- (void)viewDidLoad {
[super viewDidLoad];
// Video Setup
NSURL *currentVideoURL = [NSURL URLWithString:
self.currentVideo];
moviePlayer = [[MPMoviePlayerController alloc]
initWithContentURL:currentVideoURL];
moviePlayer.controlStyle = MPMovieControlStyleNone;
moviePlayer.scalingMode = MPMovieScalingModeAspectFit;
[moviePlayer.view setFrame: MovieView.bounds];
moviePlayer.shouldAutoplay = NO;
[MovieView addSubview:moviePlayer.view];
[moviePlayer prepareToPlay];
}该视频播放良好,除非视图是旋转到纵向,在其中的视频放置在中屏幕,只有前2/3 (水平)是可见的。如果有帮助,可以在这里看到截图:


我所希望的是,为自动收费设置的UIView MovieView (几乎全屏)将定义视频可以容纳在其中的边界,以及正确的层(commandMessageView出现在其顶部)。显然,有些东西已经过时了,但在调整了许多选项之后,并没有留下任何回旋余地。我在这里/做错了什么明显的事情吗?或者在界面构建器中有什么需要修复的东西?谢谢你提前提供帮助!
发布于 2014-02-01 01:12:48
不确定这到底是如何工作的,但是添加了一行:
[moviePlayer.view setAutoresizingMask:(UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight)];就在
[moviePlayer.view setFrame: MovieView.bounds];给了我想要的行为。
大家编码愉快!
发布于 2014-01-31 19:22:17
我也面临着一个类似的问题,除了图片。我想出来的是,你必须允许轮换,显然你已经做到了。
并实现如下内容:
-(NSUInteger)supportedInterfaceOrientations{
// if ([AppDelegate appDelegate].shoedAllowPortrait == YES) {
// return UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscape;
return UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationLandscapeLeft;
// }else{
// return UIInterfaceOrientationMaskPortrait;
// }
// return UIInterfaceOrientationMaskLandscape;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation{
return UIInterfaceOrientationPortrait;
}
- (BOOL)shouldAutorotate{
return YES;
}
-(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration: (NSTimeInterval)duration {
[self.view setNeedsDisplay];
}原因是,每次设备旋转时,都需要刷新视图或moviePlayer视图。即使是托盘添加"viewDidRoatate“和刷新那里也是,这是不工作的。
希望这有帮助,干杯
https://stackoverflow.com/questions/21486248
复制相似问题