点击某个按钮时候,晃动控件
在开发中,会遇到当输入框为空,但是用户提交信息的时候,这时候我们要给用户一个抖动提示用户。以下为方法:
if([self.searchTf.textisEqualToString:@""] ) {
[MBProgressHUDshowMessage:@"请输入搜索内容!"];
[selfloadShakeAnimationForView:self.searchTf];
}
//抖动方法
-(void)loadShakeAnimationForView:(UIView*)view
{
CALayer*lbl = [viewlayer];
CGPointposLbl = [lblposition];
CGPointy =CGPointMake(posLbl.x-10, posLbl.y);
CGPointx =CGPointMake(posLbl.x+10, posLbl.y);
CABasicAnimation* animation = [CABasicAnimationanimationWithKeyPath:@"position"];
[animationsetTimingFunction:[CAMediaTimingFunction
functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
[animationsetFromValue:[NSValuevalueWithCGPoint:x]];
[animationsetToValue:[NSValuevalueWithCGPoint:y]];
[animationsetAutoreverses:YES];
[animationsetDuration:0.08];
[animationsetRepeatCount:3];
[lbladdAnimation:animationforKey:nil];
}
参考
http://blog.csdn.net/ios_dashen/article/details/50515464