我有一个UIView
包含一个AVPlayer
来显示视频的内容。更改方向时,我需要更改视频的大小和位置。
我对调整图层大小不是很有经验,所以我在调整视频大小时遇到了问题。
我首先创建AVPlayer
并将其播放器添加到我的 videoHolderView 层:
NSURL *videoURL = [NSURL fileURLWithPath:videoPath];
self.avPlayer = [AVPlayer playerWithURL:videoURL];
AVPlayerLayer* playerLayer = [AVPlayerLayer playerLayerWithPlayer:self.avPlayer];
playerLayer.frame = videoHolderView.bounds;
playerLayer.videoGravity = AVLayerVideoGravityResizeAspect;
playerLayer.needsDisplayOnBoundsChange = YES;
[videoHolderView.layer addSublayer:playerLayer];
videoHolderView.layer.needsDisplayOnBoundsChange = YES;
然后,稍后,我更改了 videoHolderView 框架的大小和位置:
[videoHolderView setFrame:CGRectMake(0, 0, 768, 502)];
此时,我需要将 avPlayer 调整为这些相同的尺寸。这不会自动发生 - avPlayer 在 videoHolderView 中保持较小的尺寸。
如果有人可以提供帮助,我将非常感谢任何建议。
多谢你们。