我想简单地有一个循环,以便一个对象在底部不断移动屏幕。这是我的代码,它应该很容易理解。使对象在屏幕上移动iphone?
@interface ViewController()
@end
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
[self performSelector:@selector(spawnRocket) withObject:self afterDelay:2]; //delay before the object moves
}
-(void)spawnRocket{
UIImageView *rocket=[[UIImageView alloc]initWithFrame:CGRectMake(-25, 528, 25, 40)]; //places imageview right off screen to the bottom left
rocket.backgroundColor=[UIColor grayColor];
[UIView animateWithDuration:5 animations:^(){rocket.frame=CGRectMake(345, 528, 25, 40);} completion:^(BOOL finished){if (finished)[self spawnRocket];}]; //this should hopefully make it so the object loops when it gets at the end of the screen
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
做这一切后,我点击运行,所有我看到的是一个白色的屏幕上我的iPhone 6.0模拟器
PS。即时运行xcode 4.5.1
也,我有两个帐户已经几个月前,他们被禁止,因为我问的坏问题。我不确定你是否被允许在stackoverflow上拥有多个账户,所以如果你不被允许,我在这里被禁止,我不会再做账了。虽然我意识到这个网站是多么重要,我不会做任何不必要的问题。 –
可能值得提供如何创建'ViewController',这可能是一个问题。 – WDUK