我用一个不同的按钮制作一个圆圈,间隔相等。 这是它的样子:
我想这样做,以便图片不会旋转。我如何实现这一目标?这是代码。
- (void)drawWheel
{
// Drawing the Wheel view
wheelView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 275, 275)];
wheelView.center = self.view.center;
wheelView.layer.cornerRadius = wheelView.frame.size.width / 2.0;
wheelView.layer.borderColor = [UIColor whiteColor].CGColor;
//wheelView.layer.borderWidth = 0.5f;
CGFloat angleSize = 2 * M_PI / self.buttons.count;
for(int i = 0; i < self.buttons.count; i++)
{
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, wheelView.frame.size.width / 2.0, 40)];
label.layer.anchorPoint = CGPointMake(1.0f, 0.5f);
label.layer.position = CGPointMake(wheelView.bounds.size.width / 2.0, wheelView.bounds.size.height / 2.0);
label.transform = CGAffineTransformMakeRotation(angleSize * i);
label.backgroundColor = [UIColor clearColor];
UIButton *button = [self.buttons objectAtIndex:i];
button.center = CGPointMake(label.center.x, label.center.y + 15);
button.transform = CGAffineTransformRotate(label.transform, 2 * (angleSize * i));
[label addSubview:button];
[wheelView addSubview:label];
}
[self.view addSubview:wheelView];
}
答案 0 :(得分:3)
我没有检查,但你可以改变以下代码
button.transform = CGAffineTransformRotate(label.transform, 2 * (angleSize * i));
到
button.transform = CGAffineTransformMakeRotation(-1 * angleSize * i);
这里我只是将按钮旋转到相反的方向
答案 1 :(得分:2)
我认为你可以这样做......
- (void)drawWheel
{
// Drawing the Wheel view
wheelView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 275, 275)];
wheelView.center = self.view.center;
wheelView.layer.cornerRadius = wheelView.frame.size.width / 2.0;
wheelView.layer.borderColor = [UIColor whiteColor].CGColor;
//wheelView.layer.borderWidth = 0.5f;
CGFloat angleSize = 2 * M_PI / self.buttons.count;
for(int i = 0; i < self.buttons.count; i++)
{
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, wheelView.frame.size.width / 2.0, 40)];
label.layer.anchorPoint = CGPointMake(1.0f, 0.5f);
label.layer.position = CGPointMake(wheelView.bounds.size.width / 2.0, wheelView.bounds.size.height / 2.0);
label.transform = CGAffineTransformMakeRotation(angleSize * i);
label.backgroundColor = [UIColor clearColor];
UIButton *button = [self.buttons objectAtIndex:i];
button.center = CGPointMake(label.center.x, label.center.y + 15);
// change this line
button.transform = CGAffineTransformMakeRotation(-angleSize * i);
[label addSubview:button];
[wheelView addSubview:label];
}
[self.view addSubview:wheelView];
}
这里我只是以相同的角度在另一个方向上转换按钮。
即。如果标签旋转35度,则按钮旋转-35度。这意味着按钮相对于标签的审查旋转了0度。