CABasicAnimation* shake = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
shake.fromValue = [NSNumber numberWithFloat:-M_PI/32];
shake.toValue = [NSNumber numberWithFloat:+M_PI/32];
shake.duration = 0.1;
shake.autoreverses = YES; //是否重复
shake.repeatCount = 4;
[self.shakeFeedbackOverlay.layer addAnimation:shake forKey:@"shakeAnimation"];
self.shakeFeedbackOverlay.alpha = 1.0;
[UIView animateWithDuration:2.0 delay:0.0 options:UIViewAnimationOptionCurveEaseIn | UIViewAnimationOptionAllowUserInteraction animations:^{ self.shakeFeedbackOverlay.alpha = 0.0; //透明度变0则消失 } completion:nil];
转自:http://www.cnblogs.com/sell/archive/2013/02/01/2889013.html