控制video(MPMoviePlayerController)在视图中的位置
我试图定位一个视图(与一个内联video),但我有点卡住了。
我有video工作,玩得很好(在一个视图内)。 我正在使用故事板。
我已经将缩放模式设置为MPMovieScalingModeAspectFill
,这给了我很大的全屏幕裁剪视图。 只是澄清 – 我想它裁剪,这不是一个错误,但我希望它左alignment,而不是中心。
我的代码是:
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
这是我想要的模型,而不是上面的代码生成的。
任何意见将不胜感激,我是一个目标C新手! 🙂
编辑 :更新的代码,演示如何使用更大的父视图和CGRectOffset
实现此目前
- MFMailComposeViewController外观setTintColor迷失iOS 7
- 在iOS上从OpenCV ProcessImage方法更改标签文本
- MonoTouch.Foundation.MonoTouchException已经抛出了Objective-Cexception。 名称:NSInternalInconsistencyException
- 从IntPtr创buildNSException
- 如何在旋转的UIView中使用CGRectContainsPoint()
- Swift不转换Objective-C NSError **抛出
- 从Swift调用C函数
- 后台应用程序刷新检查,启用和禁用整个设备和iOS 7中的每个特定的应用程序
- 如果Facebook应用程序已安装,PFFVideosUtilslogin方法将不会执行任何操作