我正在使用 AVPlayerLayer 在我的 UIViewController 实例的背景中播放视频。当我在 iPhone 上启动我的应用程序时,我注意到放大镜以错误的方式出现。视频规格:H.264、AAC、640x360、MOV。
没有我的视频子图层的放大镜绘图内的背景。只有子视图(按钮、文本字段等)在我的放大镜中绘制。
- (void)viewDidLoad
{
[super viewDidLoad];
self.view.backgroundColor = [UIColor yellowColor];
NSURL *videoURL = [[NSBundle mainBundle] URLForResource:@"bf4" withExtension:@"mov"];
AVAsset *asset = [AVAsset assetWithURL:videoURL];
AVPlayerItem *item = [AVPlayerItem playerItemWithAsset:asset];
AVPlayer *player = [AVPlayer playerWithPlayerItem:item];
player.actionAtItemEnd = AVPlayerActionAtItemEndNone;
UIView *container = [[UIView alloc] initWithFrame:self.view.bounds];
container.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
[self.view addSubview:container];
AVPlayerLayer *layer = [AVPlayerLayer playerLayerWithPlayer:player];
[container.layer addSublayer:layer];
layer.frame = container.bounds;
layer.videoGravity = AVLayerVideoGravityResizeAspectFill;
[self.view bringSubviewToFront:self.textField];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.0f * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[player play];
});
}
有谁知道如何防止这种情况?