2013-03-04 3 views
0

아래 코드는 하위 뷰 "theSubview"를 만드는 데 사용하는 것으로, 부모 뷰 "parentView"에 추가합니다.UIBezierPath 윤곽선이 어떤 이유로보기 주위에 계속 나타납니다.

말 parentView 프레임 {{0.0, 0.0}, {100.0, 100.0}} 을 가지며 theSubview는

문제는 때이다 프레임 {{20.0, 20.0}, {20.0, 20.0}} 갖는다 내 그림이 끝나면 파란색 화살표뿐만 아니라 서브 뷰의 프레임에있는 파란색 외곽선으로 끝납니다.

내가 잘못하고있는 아이디어가 있습니까?

감사합니다.



// theSubview 
// My UIView subclass that is added to another view 
- (id)initWithFrame:(CGRect)frame 
{ 
    self = [super initWithFrame:frame]; 
    if (self) { 
     self.backgroundColor = [UIColor clearColor]; 
     self.opaque = NO; 
    } 
    return self; 
} 

- (void)drawRect:(CGRect)rect { 

    [self drawArrow];   
} 

- (void)drawArrow {  
    CGRect arrowRect; 

    arrowRect = self.bounds; 
    UIBezierPath *arrowPath = [UIBezierPath bezierPathWithRect:arrowRect]; 

// UIColor *backgrColor = [UIColor grayColor]; 
// [backgrColor setFill]; 
// [arrowPath fillWithBlendMode:kCGBlendModeNormal alpha:0.9f]; 

    UIColor *strokeColor = [UIColor blueColor]; 
    [strokeColor setStroke]; 


    CGFloat thirdOfWidth = floorf(CGRectGetWidth(self.bounds)/3); 
    CGFloat thirdOfHeight = floorf(CGRectGetHeight(self.bounds)/3); 

    [arrowPath moveToPoint:CGPointMake(thirdOfWidth, thirdOfHeight)]; 
    [arrowPath addLineToPoint:CGPointMake(thirdOfWidth * 2, thirdOfHeight + (floorf(thirdOfHeight/2)))]; 
    [arrowPath addLineToPoint:CGPointMake(thirdOfWidth, thirdOfHeight * 2)]; 
    [arrowPath setLineWidth:3.0f]; 
    [arrowPath stroke]; 


} 

답변

1

나는 알아 냈습니다. bezierPathWithRect 실제로 해당 rect로 bezierPath를 경로로 만듭니다. rect는 프레임이 아니며, b/c bezierPath는 프레임이 없습니다. b/c UIView가 아닙니다.

그것을

UIBezierPath *arrowPath = [UIBezierPath bezierPath]; 

수정에 내 위의 코드를 변경.

관련 문제