您能否具体说明为什么需要将按钮移动到三个不同的位置?无论如何,我希望你会根据一些逻辑进行更改 - 所以在头文件中定义三个枚举,例如如下所示:
typedef enum {
buttonState1,
buttonState2,
buttonState3
} buttonState;
然后,根据您的业务逻辑要求,将这些枚举变量设置在代码中的适当位置,例如:
-(void)setButtonState{
buttonState = buttonState1;
}
现在,在您的按钮 touch-up-inside 处理程序例程中,使用 switch 语句来设置适当的框架,例如,如下所示:
- (void)Switch3WayPressed:(id)sender {
if (![sender isKindOfClass:[Switch3Way class]])
return;
switch (buttonState)
{
case buttonState1:
{
CGRect frame = Switch3Way.frame;
frame.origin.x = 323;
frame.origin.y = 262;
Switch3Way.frame = frame;
break;
}
case buttonState2:
//some other rect origin based on your logic
break;
case buttonState3:
//some other rect origin based on your logic
break;
default:
break;
}