Iphone 如何切换按钮
我有3个按钮:按钮1,按钮2和按钮3。当我启动应用程序Butn1在上面时,按钮2在中间,按钮3在我的屏幕上。< /P> 当我按下其中一个按钮时,按钮必须从位置切换。 例如button1开关与button3或button1开关与button2Iphone 如何切换按钮,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]; [
我该怎么做呢?看看这个例子,看看你想用动画做什么
-(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