ios - 弹跳式动画。当您将其应用于同一属性(property)时

标签 ios animation uitableview xamarin.ios uianimation

如果我想为 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/

相关文章:

ios - 如何知道用户已经在 iOS 应用程序上完成了 Facebook 登录

ios - 来自 UITableView 的 deleteRowsAtIndexPaths :withRowAnimation: 的不规则动画

ios - Tableviewcell 调用 uiview Controller 功能无法快速 ios

ios - 如何更新表格 View 单元格?

ios - 如何在 uitextfield 中隐藏 UIPickerView?

ios - 警告 : New version of Google Maps SDK for iOS available - How do I update?

ios - 子类化的 UIScrollView

wpf - 使用 VisualStateManager 动画 MVVM ViewModel 转换——动画未运行

iphone - 从顶部/底部翻转 UIView

swift - 当 swift 中 tableView 单元格的高度扩展时更改标签文本