相关疑难解决方法(0)

iOS动画/变形形状从圆到正方形

我尝试将圆圈变成正方形,反之亦然,我几乎就在那里.然而,它没有像预期的那样动画.我想在一个正方形的所有角落同时进行动画/变形,但我得到的是以下内容:

在此输入图像描述

我使用CAShapeLayerCABasicAnimation为动画形状属性.

以下是我创建圆路径的方法:

- (UIBezierPath *)circlePathWithCenter:(CGPoint)center radius:(CGFloat)radius
{    
    UIBezierPath *circlePath = [UIBezierPath bezierPath];
    [circlePath addArcWithCenter:center radius:radius startAngle:0 endAngle:M_PI/2 clockwise:YES];
    [circlePath addArcWithCenter:center radius:radius startAngle:M_PI/2 endAngle:M_PI clockwise:YES];
    [circlePath addArcWithCenter:center radius:radius startAngle:M_PI endAngle:3*M_PI/2 clockwise:YES];
    [circlePath addArcWithCenter:center radius:radius startAngle:3*M_PI/2 endAngle:M_PI clockwise:YES];
    [circlePath closePath];
    return circlePath;
}
Run Code Online (Sandbox Code Playgroud)

这是方形路径:

- (UIBezierPath *)squarePathWithCenter:(CGPoint)center size:(CGFloat)size
{
    CGFloat startX = center.x-size/2;
    CGFloat startY = center.y-size/2;

    UIBezierPath *squarePath = [UIBezierPath bezierPath];
    [squarePath moveToPoint:CGPointMake(startX, startY)];
    [squarePath addLineToPoint:CGPointMake(startX+size, startY)];
    [squarePath addLineToPoint:CGPointMake(startX+size, startY+size)];
    [squarePath addLineToPoint:CGPointMake(startX, startY+size)];
    [squarePath closePath];
    return …
Run Code Online (Sandbox Code Playgroud)

animation calayer cabasicanimation cashapelayer ios

12
推荐指数
2
解决办法
8165
查看次数

标签 统计

animation ×1

cabasicanimation ×1

calayer ×1

cashapelayer ×1

ios ×1