我正在处理标签的抖动效果,我在 tableview 中按下单元格时调用了动画,但它不起作用。如果我在 cellForRowAtIndexPath:(NSIndexPath *)indexPath 中调用动画,它正在工作,但如果我在 didSelectRowAtIndexPath:(NSIndexPath *)indexPath 中调用它它不工作。任何人都可以帮助我吗???提前致谢
-(void)shakeAnimation:(UILabel*) label {
const int reset = 5;
const int maxShakes = 6;
//pass these as variables instead of statics or class variables if shaking two controls simultaneously
static int shakes = 0;
static int translate = reset;
[UIView animateWithDuration:0.09-(shakes*.01) // reduce duration every shake from .09 to .04
delay:0.01f//edge wait delay
options:(enum UIViewAnimationOptions) UIViewAnimationCurveEaseInOut
animations:^{label.transform = CGAffineTransformMakeTranslation(translate, 0);}
completion:^(BOOL finished){
if(shakes < maxShakes){
shakes++;
//throttle down movement
if (translate>0)
translate--;
//change direction
translate*=-1;
[self shakeAnimation:label];
} else {
label.transform = CGAffineTransformIdentity;
shakes = 0;//ready for next time
translate = reset;//ready for next time
return;
}
}];
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[self shakeAnimation:cell.MyHomeMenuCountlabel];
}