简体   繁体   English

使用CAShapeLayer的UIView上的可视性蒙版

[英]Vsibility mask on UIView with CAShapeLayer

So what I need to do is skewed UIViews (UIImageView, UIButton etc..). 因此,我需要做的是倾斜UIViews(UIImageView,UIButton等。)。

I figured I need CAShapeLayer with CGPath. 我以为我需要CGPath的CAShapeLayer。 So far so good. 到现在为止还挺好。 Then I need to assign this to myView.layer.mask. 然后,我需要将其分配给myView.layer.mask。 Its ok too. 还可以。 But what if my UIView resizes? 但是,如果我的UIView调整大小怎么办? Do I need to recalc/remake the mask or is there some place I can put this to occur automatically? 我需要重新计算/重新制作面膜吗?或者可以在某些地方使它自动发生?

I can't KVO with Categories (Objc) or extensions (Swift) since I can't globally modify dealloc method. 我无法使用类别(Objc)或扩展名(Swift)进行KVO,因为我无法全局修改dealloc方法。

So I created a Swift subclass of UIView that will do the layer masking with didSet observer on bounds . 因此,我创建了UIView的Swift子类,该子类将使用didSet观察器对bounds遮罩。 It servers as container for subview/s that are supposed to be skewed. 它用作应该倾斜的子视图的容器。

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

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