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"];
posted @ 2012-06-05 10:51  SEC.VIP_网络安全服务  阅读(95)  评论(0编辑  收藏  举报