AVPlayerLayer 动画帧变化
每当我更改 AVPlayerLayer 的帧时,视频不会立即调整大小,而是动画到新的大小。
例如:我将帧从 (0, 0, 100, 100) 更改为 (0, 0, 400, 400),视图的帧立即更改,但视频的大小会动画化为新大小。
有人遇到过这个问题吗?如果是的话,有人知道禁用默认动画的方法吗?
谢谢!
Whenever I change the frame of my AVPlayerLayer, the video is not resized immediately, but animated to the new size.
For example: I change the frame from (0, 0, 100, 100) to (0, 0, 400, 400), the view's frame is changed immediately, but the video's size is animated to the new size.
Has anyone encountered this issue? And if yes does someone know a way to disable the default animation?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
您可以尝试禁用隐式操作并使用零长度动画:
You can try disabling implicit actions and using zero length animations:
这就是我使用的:
我希望这会有所帮助。我不知道它是否是最佳实践,但它对我有用。
似乎每当使用“.frame”或“setFrame”时,它都会向图层添加动画。
This is what I used:
I hope this helps. I don't know if its best practices, but it works for me.
It seems that whenever ".frame" or "setFrame" is used, it adds animation to the layer.
处理这个问题最简单、最干净的方法是创建一个 UIView 子类,其层类为 AVPlayerLayer。执行此操作时,AVPlayerLayer 的行为就像常规 UIView 层一样。您可以更改视图的框架而不是图层,并且不会发生隐式动画。
AVPlayerLayerView.h
AVPlayerLayerView.m
您现在可以执行此操作:
要将 AVPlayerLayer 与 AVPlayer 关联,只需执行以下操作:
The easiest and cleanest way to deal with this is to create a UIView subclass that has AVPlayerLayer as its layerClass. When doing this the AVPlayerLayer will behave just like a regular UIView layer. You can change the frame of the view instead of the layer and no implicit animations will happen.
AVPlayerLayerView.h
AVPlayerLayerView.m
You can now do this:
To associate the AVPlayerLayer with an AVPlayer simply do this:
你用吗?:
Do you use ?:
以下是我在更改
playerLayer
的frame
后立即在 Swift 中执行的操作:Here is what I do in Swift right after changing the
playerLayer
'sframe
:我通过以下方式在 Swift 4 中实现了此功能:
I got this working in Swift 4 via the following:
可能是这样,在某些情况下会有帮助:
在保存播放器层的视图中添加自定义“setFrame:”设置器
Probably this, what will help in some cases:
adding custom 'setFrame:' setter in view that holds the player layer