在开发中经常会遇到一些错误提示,有了动画效果会更加醒目,下面这段代码实现的效果就是让控件左右晃动起来,
-(void)lockAnimationForView:(UIView*)view
{
CALayer *lbl = [view layer];
CGPoint posLbl = [lbl position];
CGPoint y = CGPointMake(posLbl.x-10, posLbl.y);
CGPoint x = CGPointMake(posLbl.x+10, posLbl.y);
CABasicAnimation * animation = [CABasicAnimation animationWithKeyPath:@"position"];
[animation setTimingFunction:[CAMediaTimingFunction
functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
[animation setFromValue:[NSValue valueWithCGPoint:x]];
[animation setToValue:[NSValue valueWithCGPoint:y]];
[animation setAutoreverses:YES];
[animation setDuration:0.08];
[animation setRepeatCount:3];
[lbl addAnimation:animation forKey:nil];
}