我想要做的是每十秒钟在屏幕外创建一个球,创建它时移动到屏幕中心。我怎样才能做到这一点?xcode iphone球动画
回答
在您的视图控制器设置了一个UIImageView属性为你的球,contruct球并确保它的起始位置远离creen的可视区域,然后使用一个NSTimer它将触发每十秒这卡拉斯一方法将屏幕上的球移动到中心。
-(void)viewDidLoad{
NSTimer *ballTimer = [NSTimer timerWithTimeInterval:10.0
target:self
selector:@selector(moveBall)
userInfo:nil
repeats:YES];
[[NSRunLoop mainRunLoop] addTimer:ballTimer forMode:NSRunLoopCommonModes];
myBall = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"MyBallImageFile.png"]];
myBall.center = CGPointMake(320/2, [self randNumBetween:-50:-100]);
[self.view addSubview:myBall];
}
-(void)moveBall{
myBall.center = CGPointMake(320/2, [self randNumBetween:-50:-100]);
[UIView animateWithDuration:5.0 animations:^{
myBall.center = CGPointMake(320/2, 480/2);
}];
}
---------- ------------编辑
- (CGFloat)randNumBetween:(CGFloat) min :(CGFloat) max{
CGFloat difference = max - min;
return (((CGFloat) rand()/(CGFloat)RAND_MAX) * difference) + min;
}
是的,但我想要一个屏幕外的随机位置 – 2011-04-20 09:27:54
我添加了一个函数,生成随机数,请检查我的编辑 – Sabobin 2011-04-20 09:33:58
非常感谢你 – 2011-04-20 09:36:15
- (void)viewDidLoad {
[super viewDidLoad];
myBallImage = [[UIImage imageNamed:@"ball.png"] retain];
myTimer = [NSTimer scheduledTimerWithTimeInterval:10.0 target:self selector:@selector(addBallToScreen) userInfo:nil repeats:YES];
}
- (void)viewDidUnload {
[myBallImage release];
[myTimer invalidate];
}
- (void)addBallToScreen {
//Create the imageView
UIImageView *imageView = [[UIImageView alloc] initWithImage:myBallImage];
imageView.transform = CGAffineTransformMakeTranslation(1000, 1000);
[self.view addSubview:imageView];
[imageView release];
//Animate the image view
[UIView beginAnimations:nil context:nil];
imageView.transform = CGAffineTransformMakeTranslation(50, 50);
[UIView commitAnimations];
}
是的,但我想要在屏幕之外的任意位置 – 2011-04-20 09:27:10
只需用随机值(例如使用arc4rand)替换imageView.transform = CGAffineTransformMakeTranslation(1000,1000) – ingham 2011-04-20 20:59:51
- 1. iPhone动画球体
- 2. xcode动画球iphone问题景观模式
- 3. CADisplayLink问题动画iphone xcode
- 4. 动画球体
- 5. 播放简短的动画xCode iPhone
- 6. 热气球动画
- 7. 使用javascript的球动画
- 8. Swing中的球动画
- 9. 正弦球动画CSS3
- 10. Xcode,iphone - 使图像动画在特定方向移动
- 11. iphone html动画?
- 12. iPhone UILabel动画
- 13. 动画ipad/iphone
- 14. 动画UIImageView iPhone
- 15. iphone autorotation动画
- 16. iphone iads动画
- 17. 角色移动,换球员动画
- 18. iPhone Image Zoom动画
- 19. iphone连续动画
- 20. UIView的动画iPhone
- 21. 缩放动画iPhone
- 22. iphone中的动画
- 23. iPhone相册动画
- 24. 加速iPhone动画
- 25. iphone - 错误动画
- 26. iPhone:矢量动画
- 27. Iphone手写动画
- 28. iPhone查看动画
- 29. 如何在iPhone Xcode中设置动画路线?
- 30. 用定时器进行动画制作的xcode iphone问题
VOUS devez VOUS rendreà每个槽口问题阙VOUS avez似曾相识demandé et cliquez sur la caseàcocher par laréponsela plusappareséeàl'accrepter。 Aider les gensàobtenir la reconnaissance。 Si vous n'avez pas“accepter”lesréponsesen cochant les gens sont moins susceptibles d'aider。 Vous devez augmenter votre“accepter taux«aussi proche que possible de 100% – 2011-04-26 20:40:22