之前做动画一直用这种方法[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];
代码块中,你可以对一个或多个视图同时添加多个动画效果(如改变其颜色、大小等),来实现更为复杂的动画
- 2 回答
- 0 关注
- 129 浏览
添加回答
举报
0/150
提交
取消