简体   繁体   English

UIBezierPath不画弧

[英]UIBezierPath not drawing arc

I'm trying to draw a very simple circle. 我试图画一个非常简单的圆圈。 Here is my code: 这是我的代码:

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];

then, in drawRect: 然后,在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];

I have set the center and radius, specified a line width and stroke color, and called stroke. 我设置了中心和半径,指定了线宽和笔触颜色,并称为笔触。 I have set breakpoints in drawRect to make sure the path is not nil, and it is indeed not. 我在drawRect中设置了断点,以确保路径不是nil,而实际上不是。 Just nothing is drawn. 什么也没画。

The only thing I see on screen is a green circle from the code in the view controller where I set the corner radius. 我在屏幕上看到的唯一一件事是视图控制器中设置拐角半径的代码中的绿色圆圈。 I tried calling [buttonView setNeedsDisplay]; 我尝试调用[buttonView setNeedsDisplay]; as well, and that did not help. 以及,这没有帮助。 I've tried different initializations of the bezier path as well, such as initializing with the arc instead of creating the path and then calling addArcWithCenter. 我也尝试过贝塞尔曲线的不同初始化,例如用弧形初始化而不是创建路径,然后调用addArcWithCenter。

what am I doing wrong? 我究竟做错了什么?

Pay attention that a view center is not the center of the view itself, but is the center position of the view in superview coordinates. 请注意,视图中心不是视图本身的中心,而是视图在超级视图坐标中的中心位置。 Probably you are drawing out of screen. 可能您正在画图。

The center is specified within the coordinate system of its superview and is measured in points. 中心在其父视图的坐标系内指定,并以磅为单位进行测量。 Setting this property changes the values of the frame properties accordingly. 设置此属性将相应地更改框架属性的值。

If you want to know the center of your view do this: 如果您想知道视图的中心,请执行以下操作:

CGPointMake(CGRectGetMidX(self.bounds), CGRectGetMidY(self.bounds))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM