UIView 及其子类对象 抖动效果的实现
原理:实质就是在UIView的层上加了一个动画并不断的重复
代码:
CATransform3D transform;
if
(arc4random() % 2 == 1)//这是为了让不同的View对象向左或向右转动
transform = CATransform3DMakeRotation(-0.08, 0, 0,
1.0); (左抖动的幅度,0,0,1.0)
else
transform = CATransform3DMakeRotation(0.08, 0, 0,
1.0); (右抖动的幅度,0,0,1.0)
CABasicAnimation *animation = [CABasicAnimation
animationWithKeyPath:@"transform"];
animation.toValue = [NSValue
valueWithCATransform3D:transform];
animation.autoreverses =
YES;
animation.duration = 0.1;
//间隔时间
animation.repeatCount = 10000;
//重复的次数
animation.delegate = self;
[[self
layer] addAnimation:animation forKey:@"wiggleAnimation"];
代码:
网络上志同道合,我们一起学习网络安全,一起进步,QQ群:694839022