简体   繁体   English

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

[英]iOS animate a Bezier curve with ceraiin duration

How do you animate a given Bezier curve in iOS, so that it is drawn from the start point to the end point during a given time. 如何在iOS中为给定的Bezier曲线设置动画,以便在给定时间内从起点绘制到终点。 See the animation below. 请参见下面的动画。

动画

Beizer Path Beizer路径

// 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 ImageView的

You can achieve this easily with UIViewAnimation blocks. 您可以使用UIViewAnimation块轻松实现此目的。 Get an exact image which shows entire part (for example: image1.png ). 获取显示整个零件的精确图像(例如: image1.png )。 Now here is the code: 现在这里是代码:

[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!");
                 }];

Change this code as per your requirements, like time, autorepeat or completion block, etc.. 根据您的要求更改此代码,例如时间,自动重复或完成代码等。

Hope this helps. 希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM