我正在爲正在製作的紙牌遊戲添加一些基本動畫。 (我的第一個iPhone應用程序)開始動畫之前修改iPhone動畫容器視圖
我正在創建一個自定義的UIView類「AnimationContainer」,它從image1翻轉到image2,同時從rect1移動到rect2。我的最終目的是讓這些容器中的四個同時進行轉換。
我遇到的問題是動畫不顯示image1 ...所以只有翻轉過渡的後半部分出現。
但是,如果我首先通過觸摸重置來重置動畫,那麼一切正常。換句話說,如果我一次又一次地按Flip,我只能得到一半的過渡...但是如果我先按Reset,那麼一次翻轉就完美了。
那麼,我怎樣才能讓動畫正確地重置?
以下是代碼和屏幕截圖,下面是完整鏈接:Project Zip File 700k。
alt text http://www.robsteward.com/cardflip.jpg
- (void)displayWithImage1 { //RESET button calls this
self.frame = rect1;
[image2 removeFromSuperview];
[self addSubview:image1];
[self setNeedsDisplay]; //no help: doesn't force an update before animation
}
- (void)runTheAnimation { //FLIP button calls this
[self displayWithImage1]; //<---this is what the reset button calls
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.5];
[UIView setAnimationTransition:transition forView:self cache:NO];
self.frame = rect2;
[image1 removeFromSuperview];
[self addSubview:image2];
[UIView commitAnimations];
}
謝謝!
我想出了一個半醜的解決方法。我添加了一個「虛擬」動畫,並讓我的班級成爲其setAnimationDidStopSelector的代表。虛擬動畫的持續時間爲0.0,並將視圖移動到rect1。當虛擬的停止選擇器被調用時,我從上面執行「真實」的動畫翻轉代碼。功能齊全,看起來至少有4個可以同時運行。耶,我。 LOL – Rob 2009-09-21 21:16:34
原來,解決方法可能會產生長達半秒的延遲,所以我開始賞金。必須有一種方法來發送一個容器視圖兩個圖像,並在一次轉換中將其從一個翻轉到另一個。 – Rob 2009-10-01 02:22:24