我一直使用Flash,並且在一幀和另一幀之間更改alpha值非常簡單。有沒有辦法在xcode 4中做到這一點?我正在製作徽標,我需要第一個PNG消失,而第二個PNG開始出現。 TNX!動畫alpha更改
回答
除了esqew的方法(在iOS 4之前可用,所以如果您不打算將工作限制爲僅適用於iOS 4,您應該可以使用它),還有[UIView animateWithDuration:animations:]
,它允許您執行在一個塊中的動畫。例如:
[UIView animateWithDuration:3.0 animations:^(void) {
image1.alpha = 0;
image2.alpha = 1;
}];
非常簡單,但同樣只適用於iOS 4,因此請記住這一點。
嗨,我很新,在這個,你怎麼得到兩個圖像在一個uUIView? – 2011-05-20 16:15:27
@ melisa-d我只是假設你的圖像是UIImageView實例,它們是特定視圖的子視圖。那有意義嗎? – nil 2011-05-20 23:14:12
是的,perferct的意義,我刪除了我之前提到過的數組,並單獨的UIViews,但我仍然不能動畫他們 – 2011-05-21 20:10:49
實際上這很簡單。將要發生的動畫下面的代碼:
[UIView beginAnimations:NULL context:NULL];
[UIView setAnimationDuration:3.0]; // you can set this to whatever you like
/* put animations to be executed here, for example: */
[image1 setAlpha:0];
[image2 setAlpha:1];
/* end animations to be executed */
[UIView commitAnimations]; // execute the animations listed above
你可以閱讀更多關於this document這些方法。
如果你想與你在這個問題上您的評論提到了一個結構工作:
[UIView beginAnimations:NULL context:NULL];
[UIView setAnimationDuration:3.0]; // you can set this to whatever you like
/* put animations to be executed here, for example: */
[[introAnimation objectAtIndex:0] setAlpha:0];
[[introAnimation objectAtIndex:1] setAlpha:1];
/* end animations to be executed */
[UIView commitAnimations]; // execute the animations listed above
...應該工作。
如果我正在處理這個問題:NSArray * introAnimation; \t introAnimation = [[NSArray中的alloc] initWithObjects: \t \t \t [UIImage的imageNamed:@ 「前奏000.jpg」], \t \t \t [UIImage的imageNamed:@ 「前奏001.JPG」],零]。 – 2011-05-20 16:12:24
我更新了我的答案,以納入你的'NSArray'。 – esqew 2011-05-20 20:09:32
其他的解決方案,淡入和淡出:
//Disappear
[UIView animateWithDuration:1.0 animations:^(void) {
SplashImage.alpha = 1;
SplashImage.alpha = 0;
}
completion:^(BOOL finished){
//Appear
[UIView animateWithDuration:1.0 animations:^(void) {
[SplashImage setImage:[UIImage imageNamed:sImageName]];
SplashImage.alpha = 0;
SplashImage.alpha = 1;
}];
}];
- 1. Android ImageView更改alpha動畫
- 2. 安卓更改Alpha翻譯動畫
- 3. UIStatusBar過渡動畫 - 只改變Alpha
- 4. 在UIView動畫中的Alpha更改沒有效果,罰款UIView動畫
- 5. 使用動畫更改所有標籤alpha不起作用
- 6. 使用UIView animateWithDuration立即更改Alpha:而不是動畫
- 7. MKOverlay在動畫中更改MKMapView的Alpha時跳轉
- 8. 更改alpha更改顏色
- 9. Android Alpha動畫:動畫結束後Alpha值跳回舊值
- 10. 更改動畫
- 11. 更改動畫
- 12. QT更改QImage alpha
- 13. android兩個alpha動畫
- 14. Android Alpha /翻譯動畫
- 15. 帶alpha的UISlider動畫
- 16. Android Alpha Fade動畫問題
- 17. Alpha動畫不起作用
- 18. 動畫self.view.window.frame更改
- 19. 更改動畫Cocos2d
- 20. URL更改動畫
- 21. 更改Javascript動畫
- 22. 使用ColorTransform(tint + alpha)更改alpha?
- 23. 如何實現滑動事件以動畫(例如更改alpha)視圖?
- 24. 動態更改jquery動畫
- 25. 如何更改UIImageView alpha onTouchMoved
- 26. 更改rgb位的alpha
- 27. 更改Cinder中的alpha
- 28. AS3:Graphics.lineStyle() - 僅更改ALPHA?
- 29. AlphaAnimation對象不會更改被動畫的視圖的alpha屬性,爲什麼?
- 30. 更改textview時的動畫
你開發iOS或Mac嗎? – Phlibbo 2011-05-19 19:37:02
for iPad上的iOs – 2011-05-19 21:10:30