我试图实现一个动画,当用户点击我的一个tableview单元格时发生。基本上,动画只是一个带有“+5”或“+1”这样文本的小标签,然后在衰落时向上移动(基本上就像用户评分时在视频游戏中出现的点一样)。动画正在进行时无法与UITableView交互
在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中的单元格后,您不能点击tableview中的任何其他单元格。
有没有办法阻止这种情况发生,并允许用户继续与tableview交互,就好像动画没有发生一样?
预先感谢任何与此帮助。
辉煌!那样做了。关于如何以块的方式实现它的好处是块会自动保留来自外部的视图,因此您无需担心在调用完成处理程序之前手动确保临时视图未被销毁。也给你做正式推荐的方式可疑的满意度:) – glenc 2011-03-13 16:00:04
五年后,你仍然保存我的一天。谢谢! – 2016-07-11 08:09:01