Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/116.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 按下一个按钮,它就会出现在屏幕上的其他地方_Ios_Uibutton - Fatal编程技术网

Ios 按下一个按钮,它就会出现在屏幕上的其他地方

Ios 按下一个按钮,它就会出现在屏幕上的其他地方,ios,uibutton,Ios,Uibutton,我有这个代码,所以它会改变位置一次,但当你仍然触摸时,它会停留在那里 - (IBAction)fade { [UIView beginAnimations:nil context:NULL]; [UIView setAnimationDuration:0.5]; [button setAlpha: 0]; [UIView commitAnimations]; [UIView beginAnimations:nil context:NULL]; [U

我有这个代码,所以它会改变位置一次,但当你仍然触摸时,它会停留在那里

- (IBAction)fade {
    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:0.5];
    [button setAlpha: 0];
    [UIView commitAnimations];
    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:0.5];
    [button setAlpha: 1];
    [UIView commitAnimations];
    button.center = CGPointMake(152 + 16,326 + 16);
    button.center = CGPointMake(200 + (kPlatformWidth/2),300 + (kPlatformHeight/2));
}

如何使其从此处转到随机位置?

您不应使用beginAnimations:context:

引用文件:

iOS 4.0及更高版本不鼓励使用此方法。你应该使用 使用基于块的动画方法来指定动画

您应该使用表单animateWithDuration:animations的新方法:


至于如何使按钮移动到随机位置,请使用arc4random_uniform计算新的x和y位置,并使用这些值作为视图中心的目标。

首先。。。为什么不使用基于块的动画?