抛物线动画

UIImageView *bagImgView = [[UIImageView alloc]initWithFrame:CGRectMake(20, 20, 30, 30)];

bagImgView.backgroundColor=[UIColor yellowColor];

[self.view addSubview:bagImgView];

bagImgView.image=[UIImage imageNamed:@"1.jpg"];

CAKeyframeAnimation *keyAnima1111=[CAKeyframeAnimation animationWithKeyPath:@"position"];

keyAnima1111.duration = 1.0;

keyAnima1111.repeatCount=1000;

CGMutablePathRef path1 = CGPathCreateMutable();

//注:startPoint是起点,endPoint是终点

ctrlPoint是控制点  自行调整数值可以出现理想弧度效果

CGPoint startPoint=CGPointMake(100, 480);

CGPoint endPoint=CGPointMake(300, 560);

CGPoint ctrlPoint=CGPointMake(150, 200);

CGPathMoveToPoint(path1, NULL, startPoint.x, startPoint.y);

CGPathAddQuadCurveToPoint(path1, NULL, ctrlPoint.x, ctrlPoint.y, endPoint.x, endPoint.y);

keyAnima1111.path=path1;

CGPathRelease(path1);

CABasicAnimation *animation=[CABasicAnimation animationWithKeyPath:@"transform.scale"];

animation.duration=1.0;

animation.repeatCount=1000;

animation.fromValue=[NSNumber numberWithFloat:1.0];

animation.toValue=[NSNumber numberWithFloat:0.5];

CAAnimationGroup *groupAnimation=[CAAnimationGroup animation];

groupAnimation.duration=1.0;

groupAnimation.repeatCount=1000;

groupAnimation.animations=@[animation,keyAnima1111];

[bagImgView.layer addAnimation:groupAnimation forKey:@"groupAnimation"];

动画播放完以后想要进行其他的操作,可以延迟调用

dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC));

dispatch_after(popTime, dispatch_get_main_queue(), ^(void){

}

或者

[self performSelector:@selector(delayMethod) withObject:nil afterDelay:3.0f];

你可能感兴趣的:(抛物线动画)