作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想以圆形方向旋转三个按钮,以便选定的按钮将到达中心,其他相应的按钮将相应地交换。
意味着更具体-->如果我点击“按钮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/
我是一名优秀的程序员,十分优秀!