-1

ボタン1、ボタン2、ボタン3の3つのボタンがあります。アプリケーションを起動すると、ボタン1が上、ボタン2が中央、ボタン3が画面の下に表示されます。

これらのボタンの1つを押すと、ボタンの位置を切り替える必要があります。たとえば、button1はbutton3で切り替え、button1はbutton2で切り替えます。

これはどのようにすればよいですか?

4

2 に答える 2

3

これもアニメーションで欲しいものの例を見てください...

    -(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];
    }

これは、要件のアイデアを得るこの例です。

これがお役に立てば幸いです...

于 2012-12-24T10:29:04.343 に答える
0

これは、今では古いものの代わりにブロックを使用したアニメーションソリューションですcommitAnimations

-(IBAction)clickedButton1:(id)sender{

    [UIView animateWithDuration:1
                     animations: ^{

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

}

このコードは、ボタン1と2をアニメーションで切り替えます。

于 2012-12-24T10:41:08.457 に答える