1

我有一个自定义 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 翻译这些图层会如此不稳定?有没有好的解决方案/可以达到相同效果的另一种方法是什么?

4

0 回答 0