我正在創建我的第一個iPhone本機應用程序(初學者Objective-C)。在我的主菜單標題屏幕上,我想讓背景圖像慢慢向左移動。是否可以平鋪背景圖像並移動它?我基本上試圖讓我的雲在整個背景中漂移。你會如何做到這一點?移動iPhone應用程序背景圖像
0
A
回答
0
我覺得你可以用UIScrollView做點聰明的事情。視圖加載後,您可以在後臺循環中爲視圖內容偏移添加動畫。查看ScrollViewSuite示例代碼,獲取關於滾動視圖和平鋪的一些好的提示。希望有所幫助。
2
我會添加一個UIImageView到你的屏幕(放在屏幕上的其他所有東西下)。將雲圖像放在UIImageView中,並將幀值設置爲在整個屏幕上移動。
像這樣的東西(此代碼是未經試驗)將動畫圖像視圖,向左移動在屏幕上:
cloudsImage.frame = CGRectMake(0,0,320,100); // depends on your image
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:3.0f]; // duration affects how fast it moves
cloudsImage.frame = CGRectMake(-320,0,320,100); // moves left off the screen
[UIView commitAnimations];
你也可以設置動畫相同的圖像,並從右側的同時在滑動第一個時間從左邊走出來,使它看起來像來自右邊的連續的雲層流。
cloudsImage1.frame = CGRectMake(0,0,320,100); // depends on your image
cloudsImage2.frame = CGRectMake(320,0,320,100); // start off the right edge
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:3.0f]; // duration affects how fast it moves
cloudsImage1.frame = CGRectMake(-320,0,320,100); // moves left off the screen
cloudsImage2.frame = CGRectMake(0,0,320,100); // moves left onto the screen
[UIView commitAnimations];
0
我做了類似的基於塊的動畫來實現這種效果。每個動畫塊都在一個單獨的函數中定義。
假設兩張圖像都與屏幕大小相同。
一個圖像在屏幕上完全啓動,一個圖像從屏幕左側開始,其右側與屏幕的左側邊界齊平(即,它完全偏離屏幕左側)。 讓我們調用屏幕上的圖像'A'和屏幕外圖像'B'。
function1() 第一個塊將兩個圖像的屏幕寬度向右移動 完成後,它將剛剛移出屏幕('A')的圖像設置回屏幕左側,然後調用function2()。
函數2() 第二塊移動兩個圖像屏幕寬度向右 完成時它設置在圖像剛移出屏幕(「B」)返回到左畫面,然後調用功能1()。
這裏的第一個功能:
-(void)animate_1
{
[UIView animateWithDuration:roadTimerPeriod delay:0.0
options:UIViewAnimationOptionCurveLinear|UIViewAnimationOptionAllowUserInteraction
animations: ^{
// frame 1 moves off bottom
imageAnimatedRoad1.transform = CGAffineTransformTranslate(imageAnimatedRoad1.transform,0,480);
// frame 2 moves onto top
imageAnimatedRoad2.transform = CGAffineTransformTranslate(imageAnimatedRoad1.transform,0,480);
}
completion:^(BOOL finished)
{
// reset frame 1 ready to move on
imageAnimatedRoad1.frame = CGRectMake(0,-480,320,480);
[self animate_2];
} ];
}
你認爲這是一個很好的解決方案,或者有我錯過了什麼昭然若揭?
相關問題
- 1. iPhone應用程序啓動不同背景的圖像
- 2. MVC4移動應用程序背景圖像
- 3. CSS移動背景圖像
- 4. 如何顯示iPhone應用程序的背景圖像或前景圖像
- 5. Windows Phone應用程序背景圖像
- 6. Android應用程序的背景圖像
- 7. 從應用程序設置iPhone的背景圖像
- 8. 在本地iPhone應用程序中重複背景圖像
- 9. iPhone應用程序使用MPMusicPlayer背景
- 10. Flickr iphone應用程序背景圖像縮放和褪色動畫
- 11. iphone XMPP應用程序運行背景
- 12. iPhone應用程序背景超時
- 13. 的Android - 檢測應用程序移動到背景和前景
- 14. Windows 8上的背景圖像應用程序啓動畫面
- 15. 使用jquerymobile的移動web應用程序無法正確呈現iPhone橫向背景圖像?
- 16. 使用移動應用程序splashscreen創建iphone的圖像?
- 17. 在iPhone中創建應用程序背景前景在iphone
- 18. 水平移動背景圖像
- 19. div在移動的背景圖像
- 20. 從上往下移動背景圖像
- 21. 背景圖像移動OpenGL ES2
- 22. 背景圖像中移動的jQuery
- 23. 隨機移動背景圖像
- 24. 在事件中移動iPhone的背景圖像
- 25. 不調整大小在移動/ iPhone上的背景圖像
- 26. 應用背景圖像與動態CSS
- 27. iphone啓動圖像應用程序
- 28. iOS應用背景圖像
- 29. 移動固定圖像背景css,圖像滾動
- 30. 更改和諧繪圖應用程序的背景圖像