【问题标题】:How to rotate UIButtons in Circular Direction in iOS?如何在 iOS 中以圆形方向旋转 UIButtons?
【发布时间】:2012-02-17 13:26:21
【问题描述】:

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

意味着更具体--> 如果我单击“按钮 2”,它将居中,即。在“按钮 3”的当前位置,“按钮 3”同样会切换到“按钮 1”。

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

谁能帮我实现这个目标。

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

【问题讨论】:

  • 您是否希望有人为您编写此代码,或者您可能只是忘记分享您的代码?
  • 我创建了一个带有固定 UIButtons 的示例应用程序,但我没有处理动画,所以请给我一些指导以继续。

标签: objective-c ios


【解决方案1】:

假设您将 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 属性来检测旋转的方式。但是你应该从中得到大致的想法。

【讨论】:

  • 谢谢,这有助于我创建基本的正常帧移动序列,现在我正在努力创造更好的外观。非常感谢您在这方面的指导。
【解决方案2】:

您需要查看 UIView 动画

基本上,您需要在每个按钮被按下时为每个按钮的 center 属性设置动画。很简单的东西。

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

【讨论】:

猜你喜欢
  • 2011-01-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多