【问题标题】:How to customize the shake animation in IOS's UIImageViewIOS的UIImageView中如何自定义抖动动画
【发布时间】:2013-06-25 13:29:23
【问题描述】:

我正在编写一个抖动图像功能,代码如下:

CABasicAnimation* shake = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
shake.fromValue = [NSNumber numberWithFloat:-0.2];
shake.toValue = [NSNumber numberWithFloat:+0.2];
shake.duration = 0.1;
shake.autoreverses = YES; 
shake.repeatCount = 4;
[self.imageView.layer addAnimation:shake forKey:@"imageView"];
self.imageView.alpha = 1.0;
[UIView animateWithDuration:2.0 delay:2.0 options:UIViewAnimationOptionCurveEaseIn animations:nil completion:nil];

我有两个问题:

1.上面的代码会围绕中心晃动图像(transform.rotation.z)。但是如何让图像围绕底部中心晃动呢?

2.如何控制这个抖动动画的开始和停止?例如,使图像抖动,直到从服务器获取数据完成然后停止动画。

【问题讨论】:

    标签: ios image animation shake


    【解决方案1】:

    您可以通过修改图像来做到这一点。让它高一倍,但底部是透明的。

    仅使用代码的类似解决方案: 将ImageView 放到另一个视图中...称它为imageHolderView,其中imageHolderView 是图像的两倍,但否则它只是透明的,然后摇动 that 而不仅仅是您的图像

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-12-29
      • 1970-01-01
      • 2018-05-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-12-23
      相关资源
      最近更新 更多