【发布时间】:2016-01-31 19:54:45
【问题描述】:
我有一个名为 videoView 的容器 UIView。我在该视图中添加了一个 AVPLayerLayer。我不知道如何将videoView 调整为与 avplayer 层相同的比例。使用videoGravity 并没有达到预期的效果。
AVPlayerItem* playerItem = [AVPlayerItem playerItemWithURL:path];
_videoPlayer = [[AVPlayer alloc] initWithPlayerItem:playerItem];
AVPlayerLayer *layer = [AVPlayerLayer layer];
[_avplayerLayer setPlayer:_videoPlayer];
[_avplayerLayer setBackgroundColor:[UIColor whiteColor].CGColor];
[_avplayerLayer setVideoGravity:AVLayerVideoGravityResizeAspectFill];
[_avplayerLayer setFrame:_videoView.bounds];
[_videoView.layer addSublayer:_avplayerLayer];
我正在使用自动布局,我的布局将适应 _videoView 高度的变化。
【问题讨论】:
标签: ios objective-c avplayer aspect-ratio