为什么同心圆上的角度越来越小?

时间:2012-08-21 19:42:33

标签: objective-c ios

绘制的第一个圆圈(最里面的圆圈)是可以的,但是它们变得越来越圆形了?我知道这必须与迭代有关。

//LOAD CIRCLES

circleWidth = 100;
circleHeight = 100;

for (int i = 0; i < 4; i++) {
UIView *circleView = [[UIView alloc] init];
circleView.frame = CGRectMake(0, 0, circleWidth, circleHeight);
circleView.center = self.view.center;
circleView.alpha = 0.7;
circleView.layer.cornerRadius = 50;
circleView.backgroundColor = [UIColor clearColor];
circleView.layer.borderColor = [[UIColor whiteColor] CGColor];
circleView.layer.borderWidth = 3;
circleHeight += 50;
circleWidth += 50;

[self.view addSubview:circleView];
[self.view sendSubviewToBack:circleView];

}

3 个答案:

答案 0 :(得分:2)

您必须将cornerRadius设置为circleHeight的至少一半:

circleView.layer.cornerRadius = circleHeight * 0.5f;

答案 1 :(得分:2)

也许它必须做circleView.layer.cornerRadius = 50 - 你正在增加circleHeight和circleWidth而不是cornerRadius

答案 2 :(得分:0)

您在每次迭代中增加宽度和高度,但cornerRadius仍然固定为50,如果宽度和高度为100(第一次迭代),则只会产生一个圆。您应该将cornerRadius设置为circleWidth * 0.5