为了账号安全,请及时绑定邮箱和手机立即绑定

有没有什么办法是可以指定路径做动画的?

有没有什么办法是可以指定路径做动画的?

iOS
GCT1015 2023-04-16 21:17:11
之前做动画一直用这种方法[UIView beginAnimations:@"animation" context:NULL]; [UIView setAnimationDuration:0.5f];// 新位置[UIView commitAnimations];但是解决不了View需要转向的问题。我现在需要让这个动画过程中,View有一个抖动的效果,这个实现不了,除非我用延迟,做两次动画,感觉这样很恶心。
查看完整描述

2 回答

?
Helenr

TA贡献1780条经验 获得超3个赞

用Core Animation,可以指定动画路径。
下面例子实现一个物体下落再弹起的动画

    [CATransaction begin];    [CATransaction setValue:[NSNumber numberWithFloat:ANIMATION_DURATION] forKey:kCATransactionAnimationDuration];

    CAKeyframeAnimation *positionAnimation = [CAKeyframeAnimation animationWithKeyPath:@"position"];
    CGMutablePathRef positionPath = CGPathCreateMutable();    CGPathMoveToPoint(positionPath, NULL, [theView layer].position.x, [theView layer].position.y);    CGPathAddQuadCurveToPoint(positionPath, NULL, [theView layer].position.x, - [theView layer].position.y, [theView layer].position.x, [theView layer].position.y);    CGPathAddQuadCurveToPoint(positionPath, NULL, [theView layer].position.x, - [theView layer].position.y * 1.5, [theView layer].position.x, [theView layer].position.y);    CGPathAddQuadCurveToPoint(positionPath, NULL, [theView layer].position.x, - [theView layer].position.y * 1.25, [theView layer].position.x, [theView layer].position.y);
    positionAnimation.path = positionPath;
    positionAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn];    [[theView layer] addAnimation:positionAnimation forKey:@"positionAnimation"];    CGPathRelease(positionPath);    [CATransaction commit];	

当然,在

[CATransaction begin];
...
[CATransaction commit];

代码块中,你可以对一个或多个视图同时添加多个动画效果(如改变其颜色、大小等),来实现更为复杂的动画


查看完整回答
反对 回复 2023-04-20
?
小怪兽爱吃肉

TA贡献1852条经验 获得超1个赞

Core Animation。

查看完整回答
反对 回复 2023-04-20
  • 2 回答
  • 0 关注
  • 87 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信