出于某种原因,UIBezierPath大纲一直出现在视图周围

时间:2013-03-04 05:25:13

标签: ios cocoa-touch uiview uibezierpath

下面的代码是我用来创建我的子视图“theSubview”,我将其添加到父视图“parentView”。

假设parentView的框架为{{0.0,0.0},{100.0,100.0}} andSubview具有框架{{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 个答案:

答案 0 :(得分:1)

杜,我明白了。 bezierPathWithRect 实际上使用该rect作为路径生成bezierPath。 rect不是一个框架,b / c bezierPath没有框架.b / c它不是UIView。

将我的上述代码更改为

UIBezierPath *arrowPath = [UIBezierPath bezierPath];

修复它。