經(jīng)常寫動(dòng)畫烧给,好的動(dòng)畫效果,可以使應(yīng)用的level提升好幾個(gè)檔次伤靠,
下面有一個(gè)動(dòng)畫顯得很舒服!個(gè)人表示很喜歡戴卜,在此做個(gè)記錄逾条。
//貝塞爾曲線動(dòng)畫
- (IBAction)clickAction:(UIButton *)sender {
//圖片的位置、大小(x,y,w,h)
float imageX = 40;
float imageY = 310;
float imageW = 20;
float imageH = 20;
//把圖片加到view上
UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(imageX, imageY, imageW, imageH)];
imageView.image = [UIImage imageNamed:@"cm_center_discount"];
[self.view addSubview:imageView];
CALayer *layer = [[CALayer alloc] init];
layer.contents = imageView.layer.contents;
layer.frame = imageView.frame;
layer.opacity = 1;
[self.view.layer addSublayer:layer];
//都以self.view為參考系
UIBezierPath *path = [UIBezierPath bezierPath];
//動(dòng)畫起點(diǎn)
CGPoint startPoint = CGPointMake(imageX+imageW/2, imageY+imageH/2);
[path moveToPoint:startPoint];
//動(dòng)畫終點(diǎn)
CGPoint endpoint = CGPointMake(320, 568);
//貝塞爾曲線中間點(diǎn)
float sx = startPoint.x;
float sy = startPoint.y;
float ex = endpoint.x;
float ey = endpoint.y;
float x = sx+(ex-sx)/3;
float y = sy+(ey-sy)*0.5-400;
CGPoint centerPoint = CGPointMake(x,y);
[path addQuadCurveToPoint:endpoint controlPoint:centerPoint];
CAKeyframeAnimation *animation = [CAKeyframeAnimation animationWithKeyPath:@"position"];
animation.path = path.CGPath;
animation.fillMode = kCAFillModeForwards;
animation.duration = 0.7;
animation.delegate = self;
animation.autoreverses = YES;//是否自動(dòng)退回
animation.removedOnCompletion = NO;//完成后是否移除
animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn];
[layer addAnimation:animation forKey:@"buy"];
}