iphone - 为 UIImageView 的外观添加弹跳效果

标签 iphone objective-c ipad core-animation

当我要将 UIImageView 作为 subview 显示时,如何添加弹跳效果?我是否必须使用 CoreAnimation 来执行此操作?我现在唯一的猜测是使用 CAKeyframeAnimation,如果有更好的方法请告诉我。这是我当前的代码:

 CABasicAnimation * theAnimation=[CABasicAnimation animationWithKeyPath:@"transform.translation.y"];
    theAnimation.delegate = self;
    theAnimation.duration = 1.0;
    theAnimation.fromValue = [NSNumber numberWithFloat:notif.center.y];
    theAnimation.toValue = [NSNumber numberWithFloat:notif.center.y-20];
    theAnimation.repeatCount = 3;

最佳答案

使用 CABasicAnimation 的 y 轴动画:

CGPoint origin = self.imageView.center;
CGPoint target = CGPointMake(self.imageView.center.x, self.imageView.center.y+100);
CABasicAnimation *bounce = [CABasicAnimation animationWithKeyPath:@"position.y"];
bounce.duration = 0.5;
bounce.fromValue = [NSNumber numberWithInt:origin.y];
bounce.toValue = [NSNumber numberWithInt:target.y];
bounce.repeatCount = 2;
bounce.autoreverses = YES;
[self.imageView.layer addAnimation:bounce forKey:@"position"];

如果你想实现缩小和增长,你必须添加一个 CGAffineTransformMakeScale,例如:

// grow
CGAffineTransform transform = CGAffineTransformMakeScale(1.3, 1.3);
imageView.transform = transform;

关于iphone - 为 UIImageView 的外观添加弹跳效果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7787494/

相关文章:

iphone - 错误 : expected specifier-qualifier-list before 'cv'

iphone - 使用自定义 tableview 单元格中的按钮删除行

iphone - 我的 iphone 3gs 应用程序可以在 iphone 4 上正常运行吗?

objective-c - iPhone OpenGL-ES 视频纹理

objective-c - 模态 session 需要 Mac 上的模态窗口错误

Javascript 音频在浏览器中播放,但不在 iOS 设备上播放

javascript - iPhone safari 底部栏

objective-c - 使用 NSArray 进行 C 类型的 int 比较

iphone - 如何在 iPhone 中查看 eps 文件?

ios - UIImagePickerController 和外部显示