如果我想为 UITableViewCell 设置动画,使其从左向右弹跳几次,我该怎么做?我正在尝试:
var bounds = activeCell.Bounds;
var originalLocation = bounds.Location;
var loc = originalLocation;
UIView.Animate(0.2,()=>{
loc.X = originalLocation.X + 20;
activeCell.Bounds = new RectangleF (loc, bounds.Size);
loc.X = originalLocation.X - 20;
activeCell.Bounds = new RectangleF (loc, bounds.Size);
});
它只对最后一个状态进行动画处理(即向左移动元素)。我试图将它们放在单独的 Animate
block 中 - 它没有帮助。尝试使用不同的 UIAnimationOptions
- 相同。
最佳答案
这是一篇很好的文章,解释了如何让它反弹。
http://khanlou.com/2012/01/cakeyframeanimation-make-it-bounce/
此外,还有用于计算反弹路径的公式的解释。 对于我个人的使用,我采用了计算的绝对值来模拟地面反弹。
- (void) displayNoCommentWithAnimation{
CAKeyframeAnimation *animation = [CAKeyframeAnimation animationWithKeyPath:@"position.y"];
animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];
animation.duration = 2;
int steps = 120;
NSMutableArray *values = [NSMutableArray arrayWithCapacity:steps];
double value = 0;
float e = 2.71;
for (int t = 0; t < steps; t++) {
value = 210 - abs(105 * pow(e, -0.025*t) * cos(0.12*t));
[values addObject:[NSNumber numberWithFloat:value]];
}
animation.values = values;
animation.removedOnCompletion = NO;
animation.fillMode = kCAFillModeForwards;
animation.delegate = self;
[viewThatNeedToBounce.layer addAnimation:animation forKey:nil];
}
- (void) animationDidStop:(CAAnimation *)animation finished:(BOOL)flag {
CAKeyframeAnimation *keyframeAnimation = (CAKeyframeAnimation*)animation;
[viewThatNeedToBounce.layer setValue:[NSNumber numberWithInt:210] forKeyPath:keyframeAnimation.keyPath];
[viewThatNeedToBounce.layer removeAllAnimations];
}
关于ios - 弹跳式动画。当您将其应用于同一属性(property)时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7906039/