【发布时间】:2013-08-13 07:09:15
【问题描述】:
我正在处理标签的抖动效果,我在 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];
}
【问题讨论】:
-
定义“不工作”。在你的
didSelectRowAtIndexPath方法中你从哪里得到cell? -
@maddy 找不到你???
-
我已经创建了自定义单元格并只是对其应用了动画
-
在您的
didSelectRowAtIndexPath方法中,您引用了一个名为cell的变量。这个变量是从哪里来的?请澄清您所说的“不工作”是什么意思?您是否收到编译错误、运行时错误,或者只是没有按预期工作? -
它工作正常但我想在选择一行时摇晃怎么办??
标签: ios objective-c uitableview uilabel shake