iOS使用ceraiin持续时间为Bezier曲线设置动画

时间:2014-12-10 06:42:15

标签: ios animation bezier

如何在iOS中为给定的Bezier曲线设置动画,以便在给定时间内从起点绘制到终点。请参阅下面的动画。

animation

1 个答案:

答案 0 :(得分:4)

Beizer Path

// set up properties for path
@property (nonatomic, assign) CGPath startPath;
@property (nonatomic, assign) CGPath endPath;
@property (nonatomic, strong) CAShapeLayer *pathLayer;

// create the startPath
UIBezierPath *path = [UIBezierPath //create your path using the paint code code
self.startPath = path.CGPath;

// create the end path
path = [UIBezierPath //create your path using the paint code code
self.endPath = path.CGPath;

// create the shapee layer
self.pathLayer = [CAShapeLayer layer];
self.pathLayer.path = self.startPath;
//also set line width, colour, shadows, etc...

[self.view.layer addSubLayer:self.pathLayer];

- (void)animatePath
{
    [UIView animateWithDuration:2.0
        animations^() {
            // set the animation block variables as suggested in imageview animation.
    }];
}

<强> ImageView的

您可以使用 UIViewAnimation 块轻松实现此目的。获取显示整个部分的精确图像(例如: image1.png )。现在这里是代码:

[myImageView setImage: [UIImage imageNamed:@"image1.png"]];
[myImageView setFrame: CGRectMake(0, 0, 0, 100)]; //for example width = 100 and height = 100 is required

[UIView animateWithDuration:0.5
                      delay:1.0
                    options: UIViewAnimationCurveEaseOut
                 animations:^{
                     [myImageView setFrame: CGRectMake(0, 0, 100, 100)];
                 } 
                 completion:^(BOOL finished){
                     NSLog(@"Done!");
                 }];

根据您的要求更改此代码,例如时间,自动重复或完成块等。

希望这有帮助。