2013-03-04 156 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]; 

修復它。