在開發(fā)中讹开,會(huì)遇到當(dāng)輸入框?yàn)榭罩咽樱怯脩籼峤恍畔⒌臅r(shí)候,這時(shí)候我們要給用戶一個(gè)抖動(dòng)提示用戶旦万。以下為方法:
if([self.searchTf.textisEqualToString:@""] ) {
[MBProgressHUDshowMessage:@"請(qǐng)輸入搜索內(nèi)容!"];
[selfloadShakeAnimationForView:self.searchTf];
}
//抖動(dòng)方法
-(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