2017-09-04 1 views
0

UIBezierPath bezierPathWithArcCenter으로 원을 그리려는 뷰가 있습니다. 다음과 같이 내보기의 initWithFrame은 다음과 같습니다 UIBezierPath bezierPathWithArcCenter가 올바르게 가운데 정렬되지 않았습니다.

- (instancetype)initWithFrame:(CGRect)frame 
{ 
    self = [super initWithFrame:frame]; 
    if(self == nil) { 
     return nil; 
    } 

    self.circleLayer = [CAShapeLayer layer]; 
    self.circleLayer.fillColor = UIColor.clearColor.CGColor; 
    self.circleLayer.strokeColor = UIColor.blackColor.CGColor; 
    self.circleLayer.lineWidth = 4; 
    self.circleLayer.bounds = self.bounds; 


    self.startAngle = 0.0; 
    self.endAngle = M_PI * 2; 
    CGPoint center = CGPointMake(self.frame.size.width * 0.5, self.frame.size.height * 0.5); 
    CGFloat radius = self.frame.size.height * 0.45; 
    self.circleLayer.path = [UIBezierPath bezierPathWithArcCenter:center radius:radius startAngle:self.startAngle endAngle:self.endAngle clockwise:YES].CGPath; 

    [self.layer addSublayer:self.circleLayer]; 

    self.backgroundColor = UIColor.greenColor; 

    return self; 
} 

내가 그 내 시야의 중심에 검은 원을 생성 할 것으로 예상. 그러나 실제 출력은 다음과 같습니다.
Actual output

무엇이 잘못 되었나요? 어떤 연속적인 출시가가 첨부 된 이미지처럼 그려지는 결과 -

편집 별난 부분은이 응용 프로그램 새로 설치 후 제대로 그려 것입니다. 왜?

+0

drawRect 메서드 –

+0

에서이 코드를 사용해보십시오.'self.circleLayer.frame = self.bounds;'? – Larme

+0

@Larme 잘 하위 레이어이므로 '(0, 0)'원점이 있어야합니다. 아니면 내가 틀렸어? –

답변

0

이유는 iOS의 버그 인 것 같습니다. CAShapeLayer는 경계가 그것을 검사에 제대로

self.circleLayer.bounds = self.bounds; 

설정이 레이어의 기원과 크기가 괜찮지 만, 를 설치 한 후 응용 프로그램의 첫 출시 후. 이후에 앱을 출시하면 그 크기는 (0, 0)이됩니다. 앱을 제거하고 다시 설치하면 원이 올바르게 그려집니다. .

레이어의 프레임을 다시 도로 아래쪽으로 설정하여 고정 시켰습니다.

관련 문제