Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/templates/2.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
Iphone 如何切换按钮_Iphone_Ios_Button - Fatal编程技术网

Iphone 如何切换按钮

Iphone 如何切换按钮,iphone,ios,button,Iphone,Ios,Button,我有3个按钮:按钮1,按钮2和按钮3。当我启动应用程序Butn1在上面时,按钮2在中间,按钮3在我的屏幕上。< /P> 当我按下其中一个按钮时,按钮必须从位置切换。 例如button1开关与button3或button1开关与button2 我该怎么做呢?看看这个例子,看看你想用动画做什么 -(IBAction)button1_Clicked:(id)sender{ [UIView beginAnimations:nil context:NULL]; [

我有3个按钮:按钮1,按钮2和按钮3。当我启动应用程序Butn1在上面时,按钮2在中间,按钮3在我的屏幕上。< /P> 当我按下其中一个按钮时,按钮必须从位置切换。 例如button1开关与button3或button1开关与button2


我该怎么做呢?

看看这个例子,看看你想用动画做什么

    -(IBAction)button1_Clicked:(id)sender{

        [UIView beginAnimations:nil context:NULL];
        [UIView setAnimationDuration:0.3];
        CGRect btnframe = button1.frame;
        button1.frame = button3.frame;
        button3.frame = btnframe;
///Also you can switch the buttons with center points of buttons like...
/*
        CGPoint btn1center = button1.center;
        button1.center = button3.center;
        button3.center = btn1center;
*/

     //This bellow two lines for your requirement with change the function behind the buttons also...

       // [button1 addTarget:self action:@selector(button3_Clicked:) forControlEvents:UIControlEventTouchUpInside];
       // [button3 addTarget:self action:@selector(button1_Clicked:) forControlEvents:UIControlEventTouchUpInside];
        [UIView commitAnimations];
    }
这是一个示例,从中您可以了解您的需求。


希望这对您有所帮助……

这里有一个动画解决方案,使用块而不是现在旧的
commitAnimations

-(IBAction)clickedButton1:(id)sender{

    [UIView animateWithDuration:1
                     animations: ^{

             CGPoint center = button1.center;
             button1.center = button2.center;
             button2.center = center;
    }];

}
此代码使用动画切换按钮1和2