问题
I'm trying to position a view (with an inline video) but I'm a little stuck.
I've got the video working and playing well (inside the a view). I'm using storyboards.
I've already set the scaling mode to MPMovieScalingModeAspectFill
which gives me my great full screen cropped view. Just to clarify - I WANT it to crop, it's not a mistake, but I want it left aligned and not centred.
My code is:
VideoViewController.h
@interface VideoViewController : UIViewController
@property (strong, nonatomic) MPMoviePlayerController *moviePlayer;
@property (weak, nonatomic) IBOutlet UIView *videoView;
@end
VideoViewController.m
@implementation VideoViewController
@synthesize moviePlayer;
@synthesize videoView;
- (void)viewDidLoad
{
[super viewDidLoad];
//Set parent view to be larger (let's us offset video later on)
CGRect newSize = CGRectMake(0,0, 960, 568);
[videoView setBounds:newSize];
NSURL *theurl = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"test" ofType:@"mp4"]];
moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:theurl];
moviePlayer.scalingMode = MPMovieScalingModeAspectFill;
//Set to parent bounds
[moviePlayer.view setFrame: videoView.bounds];
[videoView addSubview:moviePlayer.view];
//Offset video inside view (as required)
moviePlayer.view.frame = CGRectOffset( moviePlayer.view.frame, -320, 0 );
//Play video
[moviePlayer prepareToPlay];
[moviePlayer play];
}
@end
And this is a mockup of what I want versus what the code above is producing.
Any advice would be appreciated, I'm am an Objective C newb! :)
EDIT: Updated code to demonstrate how I have achieved this now using a larger parent view and CGRectOffset
来源:https://stackoverflow.com/questions/22702287/control-position-of-video-mpmovieplayercontroller-inside-a-view