Ios6 使用UIBeizerpath在imageContext上绘制圆角矩形无效

Ios6 使用UIBeizerpath在imageContext上绘制圆角矩形无效,ios6,core-graphics,Ios6,Core Graphics,当用户触摸在iPad上移动时,我需要画一个圆形的矩形。 这是我的代码,它在触摸移动时显示黑色圆形矩形,在触摸结束时显示所选颜色。谁能告诉我原因吗 - (void)drawRect:(CGRect)rect { [path setLineWidth:lineSize]; [selectedColor setStroke]; [drawImage drawInRect:rect]; // (3) [path fill]; } -(void)touches

当用户触摸在iPad上移动时,我需要画一个圆形的矩形。 这是我的代码,它在触摸移动时显示黑色圆形矩形,在触摸结束时显示所选颜色。谁能告诉我原因吗

- (void)drawRect:(CGRect)rect
{

    [path setLineWidth:lineSize];
    [selectedColor setStroke];

    [drawImage drawInRect:rect]; // (3)
      [path fill];
  }

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    UITouch *touch = [touches anyObject];
    CGPoint p = [touch locationInView:self];
    startPoint=p;
}

-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
    UITouch *touch = [touches anyObject];
    CGPoint p = [touch locationInView:self];
      float x=startPoint.x;
        float y=startPoint.y;
        float z=p.x-startPoint.x;
        float a=p.y-startPoint.y;

        if (z<0 && a<0) {
            x=p.x;
            y=p.y;
            z=startPoint.x-p.x;
            a=startPoint.y-p.y;
        }
        else if (a<0)
        {
            x=startPoint.x;
            y=startPoint.y;
            z=p.x-startPoint.x;
            a=startPoint.y-p.y;
        }
        else if(z<0)
        {
            x=startPoint.x;
            y=startPoint.y;
            z=startPoint.x-p.x;
            a=p.y-startPoint.y;

        }

        path = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(x,y,z,a) cornerRadius:10.0];

        [self setNeedsDisplay];

}

-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
    UITouch *touch = [touches anyObject];
    CGPoint p = [touch locationInView:self];
       [self drawBitmap];
        [self setNeedsDisplay];
  }

- (void)drawBitmap // (3)
{
    UIGraphicsBeginImageContextWithOptions(self.bounds.size, YES, 0.0);
     [selectedColor setStroke];
   if (!drawImage) // first draw; paint background white by ...
    {
        UIBezierPath *rectpath = [UIBezierPath bezierPathWithRect:self.bounds]; // enclosing bitmap by a rectangle defined by another UIBezierPath object
        [[UIColor whiteColor] setFill];

        [rectpath fill]; // filling it with white
    }

    [drawImage drawAtPoint:CGPointZero];
       [selectedColor setFill];
        [path fill];
          drawImage = UIGraphicsGetImageFromCurrentImageContext();
   UIGraphicsEndImageContext();
}
-(void)drawRect:(CGRect)rect
{
[路径设置线宽:线宽];
[选择颜色设置行程];
[drawImage drawInRect:rect];/(3)
[路径填充];
}
-(无效)触摸开始:(NSSet*)触摸事件:(UIEvent*)事件
{
UITouch*touch=[触摸任何对象];
CGP点=[触摸位置视图:自];
起始点=p;
}
-(无效)触摸移动:(NSSet*)触摸事件:(UIEvent*)事件
{
UITouch*touch=[触摸任何对象];
CGP点=[触摸位置视图:自];
浮动x=起始点x;
浮动y=起始点y;
float z=p.x-startPoint.x;
浮动a=p.y-起始点y;

如果(z编辑
initWithFrame
方法,使UIView的背景为白色

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
        self.backgroundColor = [UIColor clearColor];
    }
    return self;
}