【发布时间】:2011-03-12 15:51:52
【问题描述】:
我正在尝试实现当用户点击我的一个 tableview 单元格时发生的动画。基本上,动画只是一个带有诸如“+5”或“+1”之类的文本的小标签,然后在消失的同时向上移动(基本上就像用户评分时电子游戏中出现的点一样)。
在我的控制器的tableView:didSelectRowAtIndexPath: 实现中,我正在执行以下操作(此处为简单起见):
CGRect toastFrame = /* figure out the frame from the cell frame here */;
UILabel *toast = [[UILabel alloc] initWithFrame:toastFrame];
toast.text = [NSString stringWithFormat:@"+%d", 5];
toast.backgroundColor = [UIColor clearColor];
toast.userInteractionEnabled = NO; // hoped this would work but it doesn't
[tableView addSubview:toast];
[UIView
animateWithDuration:1.0
animations:^
{
toast.alpha = 0.0;
toast.transform = CGAffineTransformMakeTranslation( 0.0, -44.0 );
}
completion:^ (BOOL finished)
{
[toast removeFromSuperview];
}];
[toast release];
吐司看起来很漂亮,看起来很棒。问题是在动画完成之前,tableview 会停止接收触摸事件。这意味着在点击表格视图中的一个单元格后的一秒钟内,您不能点击表格视图中的任何其他单元格。
有没有办法阻止这种情况发生并允许用户继续与 tableview 交互,就好像动画根本没有发生一样?
在此先感谢您提供任何帮助。
【问题讨论】:
标签: iphone animation uitableview