[英]UIBezierPath not drawing arc
我試圖畫一個非常簡單的圓圈。 這是我的代碼:
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。
我究竟做錯了什么?
請注意,視圖中心不是視圖本身的中心,而是視圖在超級視圖坐標中的中心位置。 可能您正在畫圖。
中心在其父視圖的坐標系內指定,並以磅為單位進行測量。 設置此屬性將相應地更改框架屬性的值。
如果您想知道視圖的中心,請執行以下操作:
CGPointMake(CGRectGetMidX(self.bounds), CGRectGetMidY(self.bounds))
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.