简体   繁体   English

将 videoGravity 设置为 AVLayerVideoGravityResizeAspectFill 对 iOS 5.0 没有影响

[英]Setting videoGravity to AVLayerVideoGravityResizeAspectFill has no effect on iOS 5.0

I have implemented a custom movie player with AVPlayer .我已经使用AVPlayer实现了一个自定义电影播放器​​。 On setting the value of videoGravity in AVPlayerLayer to AVLayerVideoGravityResizeAspectFill I see the desired effect in iOS 4.2, 4.3 .在将AVPlayerLayerAVLayerVideoGravityResizeAspectFill的值设置为 AVLayerVideoGravityResizeAspectFill 时,我在iOS 4.2, 4.3看到了所需的效果。 But somehow on iOS 5.0 it has got no effect.但不知何故在iOS 5.0它没有效果。 Is anybody seeing a similar issue?有人看到类似的问题吗? Am I doing something wrong?难道我做错了什么?

On iOS5 you should reset layers bounds after setting videoGravity.在 iOS5 上,您应该在设置 videoGravity 后重置图层边界。

This worked for me:这对我有用:

((AVPlayerLayer *)[self layer]).videoGravity = AVLayerVideoGravityResizeAspectFill;
((AVPlayerLayer *)[self layer]).bounds = ((AVPlayerLayer *)[self layer]).bounds;

EDITED: "self" points to a PlayerView (subclass of UIView) object from example "Putting all together": https://developer.apple.com/library/ios/#documentation/AudioVideo/Conceptual/AVFoundationPG/Articles/02_Playback.html编辑: “self”指向示例“Putting all together”中的 PlayerView(UIView 的子类)对象: https : //developer.apple.com/library/ios/#documentation/AudioVideo/Conceptual/AVFoundationPG/Articles/02_Playback。 html

Found the solution to this issue.找到了这个问题的解决方案。 Tick checkbox "Clip Subviews" in IB for the view with the layer you're going to attach the video player to.勾选 IB中的“剪辑子视图”复选框,以查看您要将视频播放器附加到的图层。 Then, set the AVLayerVideoGravityResizeAspectFill of your AVPlayerLayer object.然后,设置 AVPlayerLayer 对象的 AVLayerVideoGravityResizeAspectFill。 If you don't have the view in IB but you're creating it programmatically, set its clipsToBounds property to YES.如果您在 IB 中没有视图,但您正在以编程方式创建它,请将其clipsToBounds属性设置为 YES。

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

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