Objective c 使按钮滑入视图

Objective c 使按钮滑入视图,objective-c,uibutton,Objective C,Uibutton,我正在制作一个游戏,我试图让播放按钮在视图加载时滑到屏幕上,并在到达中心时停止(而不是在视图加载时按钮已经出现在屏幕上) 我的viewDidLoad函数中有以下代码: - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. while(playButton.center.x != 71) playButton

我正在制作一个游戏,我试图让播放按钮在视图加载时滑到屏幕上,并在到达中心时停止(而不是在视图加载时按钮已经出现在屏幕上)

我的viewDidLoad函数中有以下代码:

- (void)viewDidLoad
{

[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.

while(playButton.center.x != 71) 
    playButtonTimer = [NSTimer scheduledTimerWithTimeInterval:0.002 target:self selector:@selector(playButtonMove) userInfo:nil repeats:YES];

}
-(void)playButtonMove {
playButton.center = CGPointMake(playButton.center.x - 1, playButton.center.y);
}
此时发生的一切就是当我运行应用程序时,屏幕保持黑色,当我关闭应用程序时,Xcode中会出现一个窗口,显示“由于内存错误而终止”

编辑: 以下是我的playButtonMove函数:

- (void)viewDidLoad
{

[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.

while(playButton.center.x != 71) 
    playButtonTimer = [NSTimer scheduledTimerWithTimeInterval:0.002 target:self selector:@selector(playButtonMove) userInfo:nil repeats:YES];

}
-(void)playButtonMove {
playButton.center = CGPointMake(playButton.center.x - 1, playButton.center.y);
}
删除:

while(playButton.center.x != 71) 
    playButtonTimer = [NSTimer scheduledTimerWithTimeInterval:0.002 target:self selector:@selector(playButtonMove) userInfo:nil repeats:YES];
并将其添加到您的文件中:

- (void)viewDidAppear:(BOOL)animated {
    [UIView animateWithDuration:.25 animations:^{
        playButton.center = CGPointMake(71, playButton.center.y);
    }];
}

你的应用程序将永远运行,因为你在playbuttontimer有机会启动之前重新分配了它。因此,您的while语句将始终为真。基本上,你的应用现在正在做的就是创建成千上万的NSTimer,直到它崩溃。你所做的不应该用于动画。使用苹果的内置动画api。

为什么投票失败。。。