Vij*_*jay 6 objective-c uitableview uilabel shake ios
我正在使用标签的摇动效果我在桌面视图中按下单元格时调用了动画但是它不起作用.如果我在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];
}
Run Code Online (Sandbox Code Playgroud)
有两种方法可以做到这一点:
1.试试这个功能:
NSArray *arrIndexPath = [NSArray arrayWithObject:indexPath];
[dropTable reloadRowsAtIndexPaths:arrIndexPath withRowAnimation:UITableViewRowAnimationFade];
Run Code Online (Sandbox Code Playgroud)
在 didSelectRowAtIndexPath 函数中。
仅在 cellForRowAtIndexPath 中制作动画。
2. 在 cellForRowAtIndexPath 中为单元格分配标签属性。
cell.tag = indexPath.row.
Run Code Online (Sandbox Code Playgroud)
在 didSelectRowAtIndexPath 中:
然后使用表的子视图,获取等于indexPath.row的cell.tag并获取相同单元格的引用,然后执行动画:
for (MyHomeViewCell *cell in [table subviews]) { // change name of table here
if ([cell isKindOfClass:[MyHomeViewCell class]]) {
if (cell.tag == indexPath.row) {
[self shakeAnimation:cell.MyHomeMenuCountlabel];
}
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4203 次 |
| 最近记录: |