如何在iOS中以圆形方向旋转UIButtons?

时间:2012-02-17 13:26:21

标签: objective-c ios

我想以圆形方向旋转三个按钮,以便选定按钮将到达中心,其他相应按钮将相应地进行交换。

更具体的意思 - >如果我点击“按钮2”,它将成为中心即。在“按钮3”的当前位置,“按钮3”同样将换成“按钮1”。

之后如果再次单击该按钮(按钮2),它应该转到下一页(Next ViewContoller)。

任何人都可以帮助我实现这一目标。

如果可能,请提供示例应用程序的任何示例代码或链接。

2 个答案:

答案 0 :(得分:2)

假设您将3个按钮声明为ivars,那么您需要执行以下操作:

- (void)rotateLeft {
    CGRect frame1 = button1.frame;
    CGRect frame2 = button2.frame;
    CGRect frame3 = button3.frame;
    [UIView animateWithDuration:.5 animations:^{
        [button1 setFrame:frame3];
        [button2 setFrame:frame1];
        [button3 setFrame:frame2];
    }];
}

- (void)rotateRight {
    CGRect frame1 = button1.frame;
    CGRect frame2 = button2.frame;
    CGRect frame3 = button3.frame;
    [UIView animateWithDuration:.5 animations:^{
        [button1 setFrame:frame2];
        [button2 setFrame:frame3];
        [button3 setFrame:frame1];
    }];
}

- (IBAction)buttonPressed:(id)sender {
    UIButton* clicked = (UIButton*)sender;
    if (clicked.frame.origin.x == 20) {
        [self rotateLeft];
    } else if (clicked.frame.origin.x == 228) {
        [self rotateRight];
    } else {
        [self.navigationController pushViewController:[[NextController alloc] init] animated:YES];
    }
}

这使用 frame 属性来检测旋转的方式。但你应该从中得到一般的想法。

答案 1 :(得分:-1)

您需要查看 UIView动画

基本上,当按下其中一个按钮时,您需要为每个按钮的 center 属性设置动画。非常简单的东西。

如果您需要帮助,网上有大量的教程。