我有一个自定义的UIView,它应该是一个圆形矩形,当你开始在里面编辑UILabel时,圆形矩形会增长它的形状(CAShapeLayer蒙版路径和轮廓路径上的CABasic动画)。所以要清楚,自定义UIView的组织方式如下:
MyCustomView有一个ClipView。 ClipView使用drawRect绘制圆角矩形的背景。 (clipview ==视图被剪裁)
然后,我调用以下代码来执行CAShapeLayer操作:
//0. CLIP
shapeLayer = [CAShapeLayer layer];
CGRect shapeRect = self.bounds;
[shapeLayer setBounds:shapeRect];
[shapeLayer setPosition:CGPointMake((shapeRect.size.width)/2.0f, (shapeRect.size.height)/2.0f)];
[shapeLayer setFillColor:[[UIColor colorWithRed:0 green:1 blue:0 alpha:1.0f] CGColor]];
[shapeLayer setStrokeColor:[[UIColor redColor] CGColor] ];
[shapeLayer setLineWidth:1];
[shapeLayer setLineJoin:kCALineJoinRound];
[shapeLayer setOpacity:1];
CGRect shapeLayerPathRect = CGRectMake(0, 0, self.bounds.size.width, 44.0f);
shapeLayer.path = [self roundRectPathForRectangle:shapeLayerPathRect andRadius:CORNER_RADIUS];
[[self.clipView layer] setMask:shapeLayer];
//1. draw the shaded outline of a round rectangle
outlineLayer = [self topDownShadowShapeLayer]; //setup for my CAShapeLayer, involving shadow stuff, line color, etc
outlineLayer.path = [self roundRectPathForRectangle:shapeLayerPathRect andRadius:CORNER_RADIUS];
[self.clipView.layer addSublayer:outlineLayer];
虽然动画的收益是最快的方法(拉伸两个CAShapeLayers),但整个元素(MyCustomView)会导致一切都变慢!例如,继续使用UIView动画,当MyCustomView在ScrollView中时,它非常有趣。
我最担心的是UIScrollView问题。为什么UIScrollView翻译这些图层会如此不稳定?有没有一个好的解决方案/什么是另一种可以达到同样效果的方法?