小编mur*_*b83的帖子

(iOS)如何使用shapeLayer为圆角矩形设置动画?

我试图动画圆角矩形的宽度,问题是当从更大的宽度变为更宽的宽度时,动画会进行"像差轻松跳跃".

这是代码:

shapeLayer = [CAShapeLayer layer];
shapeRect = CGRectMake(0.0f, 0.0f, 150.0f, 200.0f);
[shapeLayer setBounds:shapeRect];
[shapeLayer setPosition:CGPointMake(iniPosX, 80.0f)];
[shapeLayer setFillColor:[[UIColor blackColor] CGColor]];
[shapeLayer setStrokeColor:[[UIColor clearColor] CGColor]];
[shapeLayer setLineWidth:1.0f];
[shapeLayer setLineJoin:kCALineJoinRound];
[shapeLayer setOpacity:0.2];
path = [UIBezierPath bezierPathWithRoundedRect:shapeRect cornerRadius:15.0];
[shapeLayer setPath:path.CGPath];
[self.layer addSublayer:shapeLayer];
Run Code Online (Sandbox Code Playgroud)

当我开始动画时:

- (void)adjustSelectorToPosAndSize:(float)posX andWidth:(float)width
{
    shapeRect = CGRectMake(0.0f, 0.0f, width, 200.0f);
    [shapeLayer setBounds:shapeRect];
    [shapeLayer setPosition:CGPointMake(posX, 80.0f)];
    path = [UIBezierPath bezierPathWithRoundedRect:shapeRect cornerRadius:15.0];
    [shapeLayer setPath:path.CGPath];
}
Run Code Online (Sandbox Code Playgroud)

我究竟做错了什么?

animation core-animation shape cashapelayer ios

5
推荐指数
1
解决办法
4226
查看次数

标签 统计

animation ×1

cashapelayer ×1

core-animation ×1

ios ×1

shape ×1