我試圖實現一個動畫,當用戶點擊我的一個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