CALayers没有根据UIView的界限变化调整大小。为什么? [英] CALayers didn't get resized on its UIView's bounds change. Why?
本文介绍了CALayers没有根据UIView的界限变化调整大小。为什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个 UIView
,它在其图层中添加了大约8个不同的 CALayer
子图层。
如果我修改了视图的边界(动画),那么视图本身会缩小(我用 backgroundColor
检查了它),但子图层的大小保持不变。
I have a UIView
which has about 8 different CALayer
sublayers added to its layer.
If I modify the view's bounds (animated), then the view itself shrinks (I checked it with a backgroundColor
), but the sublayers' size remains unchanged.
如何解决这个问题?
推荐答案
我使用的是Solin使用的相同方法,但该代码中存在拼写错误。该方法应该是:
I used the same approach that Solin used, but there's a typo in that code. The method should be:
- (void)layoutSubviews {
// resize your layers based on the view's new bounds
mylayer.frame = self.bounds;
}
出于我的目的,我一直希望子图层的大小完整父视图。将该方法放在视图类中。
For my purposes, I always wanted the sublayer to be the full size of the parent view. Put that method in your view class.
这篇关于CALayers没有根据UIView的界限变化调整大小。为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文