2010-10-21 134 views
0

我想要在視圖中使用圖像,像HTML中的選取框一樣移動,從一端移動到另一端。 任何人都可以爲我提供該代碼如何做到這一點。圖像與動畫在iphone

在此先感謝n請幫我解決這個問題。

+1

對不起,給我一個代碼的問題一般不歡迎在這裏。你必須嘗試自己做一些事情,並詢問你在這個過程中遇到的具體問題... – Vladimir 2010-10-21 10:32:07

回答

1

這是其在iOS系統中引入的新模塊API 4.0 使用這個,如果你還沒有在4.0

CABasicAnimation *theAnimation;   
theAnimation=[CABasicAnimation animationWithKeyPath:@"transform.translation.x"]; 
theAnimation.duration=1; 
theAnimation.repeatCount=2; 
theAnimation.autoreverses=YES; 
theAnimation.fromValue=[NSNumber numberWithFloat:0]; 
theAnimation.toValue=[NSNumber numberWithFloat:-60]; 
[view.layer addAnimation:theAnimation forKey:@"animateLayer"]; 

這段代碼移動視圖60個像素向左,然後回到它原來的位置 [請不要忘記投票,如果你發現這個答案有用:-)]

+0

是的兄弟,這是我使用iPhone 3.2.1 SDK的原因,所以得到的問題。我會嘗試它tommorow.Sure我會投票給你,但我需要15名聲譽,我有11但有人投我倒。 – Sabby 2010-10-22 14:30:11

+0

Hummm現在明白了,謝謝親愛的........ – Sabby 2010-11-04 05:32:47

0

使用的UIView的過渡效果..

[UIView AnimateWithDuration: delay: options: animations: completion: ]; 

梅索德。 重複轉換有一些很好的效果。

+0

感謝好友,我將使用這種方法... – Sabby 2010-10-22 11:57:41

+0

[UIView AnimateWithDuration:3 delay:1 options:nil animations:@「logo(1 ).png「,@」sabby.png「完成:YES];我嘗試過這樣但它顯示警告訊息。請讓我知道錯誤在哪裏。 – Sabby 2010-10-22 12:03:10