UIBezierPath不绘制弧

时间:2016-03-16 14:56:24

标签: ios core-graphics uibezierpath

我想画一个非常简单的圆圈。这是我的代码:

CameraButtonView *buttonView = [[CameraButtonView alloc]initWithFrame:CGRectMake((self.view.frame.size.width / 2) - 45, self.view.frame.size.height * 0.8, 90, 90)];
buttonView.layer.cornerRadius = buttonView.frame.size.width / 2;
buttonView.layer.borderWidth = 2;
buttonView.backgroundColor = [UIColor clearColor];
buttonView.layer.borderColor = [UIColor greenColor].CGColor;
buttonView.clipsToBounds = YES;

[previewView addSubview:buttonView];

然后,在drawRect:

 UIBezierPath *path1 = [UIBezierPath bezierPath];
[path1 addArcWithCenter:self.center radius:(20) startAngle:0 endAngle:6.28 clockwise:YES];
[path1 setLineWidth:6];
[[UIColor redColor] setStroke];
[path1 stroke];

我设置了中心和半径,指定了线宽和笔触颜色,并调用了笔触。我在drawRect中设置断点以确保路径不是nil,而实际上并非如此。什么都没画。

我在屏幕上看到的唯一一个是视图控制器中代码的绿色圆圈,我在其中设置了角半径。我试过调用[buttonView setNeedsDisplay];同样,这没有帮助。我也尝试过贝塞尔路径的不同初始化,例如用弧初始化而不是创建路径,然后调用addArcWithCenter。

我做错了什么?

1 个答案:

答案 0 :(得分:2)

注意视图中心不是视图本身的中心,而是超视图坐标中视图的中心位置。可能你正在画出画面。

  

中心在其超视图的坐标系内指定   并以分数衡量。设置此属性会更改值   相应的框架属性。

如果您想知道视图的中心,请执行以下操作:

CGPointMake(CGRectGetMidX(self.bounds), CGRectGetMidY(self.bounds))
相关问题