gpt4 book ai didi

objective-c - 如何在 iOS 中以圆形方向旋转 UIButton?

转载 作者:行者123 更新时间:2023-11-29 04:47:59 25 4
gpt4 key购买 nike

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

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

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

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

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

最佳答案

假设您将 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属性来检测旋转方向。但您应该从中了解总体思路。

关于objective-c - 如何在 iOS 中以圆形方向旋转 UIButton?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9329068/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com