简体   繁体   English

当videoGravity设置为AVLayerVideoGravityResizeAspectFill时,AVPlayerLayer视频“溢出”

[英]AVPlayerLayer video “overspilled” when videoGravity set to AVLayerVideoGravityResizeAspectFill

I've set up the custom UIView with AVPlayerLayer as suggested on the Apple Developer Library. 我已经按照Apple Developer Library上的建议,使用AVPlayerLayer设置了自定义UIView。 Everything works fine, but when I set the videoGravity of the AVPlayerLayer to AVLayerVideoGravityResizeAspectFill, it seems that the parts that are outside of the frame are visible as well. 一切正常,但是当我将AVPlayerLayer的videoGravity设置为AVLayerVideoGravityResizeAspectFill时,看起来框架外的部分也可见。 It appears to have an alpha on it too. 它似乎也有一个alpha。

I tried setting masksToBounds = YES but it didn't seem to solve the problem. 我尝试将masksToBounds设置为YES,但似乎无法解决问题。

Any ideas? 有任何想法吗?

You should select the checkbox "Clip subviews" of your AVPlayerLayerView in Xcode. 您应该选中Xcode中AVPlayerLayerView的复选框“ Clip subviews”。 Or you need to set the property accordingly to YES. 或者您需要将属性相应地设置为YES。

I run into the same issue, and fix it by switch to AVLayerVideoGravityResizeAspect. 我遇到了同样的问题,并通过切换到AVLayerVideoGravityResizeAspect进行了修复。 AVLayerVideoGravityResizeAspect ensure the preview layer resize inside your frame bounds. AVLayerVideoGravityResizeAspect确保预览图层在框架范围内调整大小。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM