我正在创建我的第一个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. 更改和谐绘图应用程序的背景图像