2013-10-24 13 views
8

मैंने उप-वर्गीकृत UIView में आकर्षित करने के लिए ऑनलाइन एक ट्यूटोरियल का पालन किया। ट्यूटोरियल ने एक सफेद पृष्ठभूमि के साथ एक UIView दिखाया, मैंने बस सुपर के बीजी रंग को बदलकर इसे ठीक किया। समस्या यह है कि, जब अंत छूता है, पृष्ठभूमि स्पष्ट नहीं रहती है। मुझे पता नहीं है। मैंने बस भरने के रंग को [uicolor clearcolor] पर सेट करने का प्रयास किया; असफल। यहाँ कोड मैं का उपयोग कर रहा है:ब्लैक पृष्ठभूमि?

@implementation CachedLIView 
{ 
    UIBezierPath *path; 
    UIImage *incrementalImage; // (1) 
} 

- (id)initWithCoder:(NSCoder *)aDecoder 
{ 
    if (self = [super initWithCoder:aDecoder]) 
    { 
     [self setMultipleTouchEnabled:NO]; 
     [self setBackgroundColor:[UIColor whiteColor]]; 
     path = [UIBezierPath bezierPath]; 
     [path setLineWidth:2.0]; 
    } 
    return self; 
} 

- (void)drawRect:(CGRect)rect 
{ 
    [incrementalImage drawInRect:rect]; // (3) 
    [path stroke]; 
} 


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

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

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event // (2) 
{ 
    UITouch *touch = [touches anyObject]; 
    CGPoint p = [touch locationInView:self]; 
    [path addLineToPoint:p]; 
    [self drawBitmap]; // (3) 
    [self setNeedsDisplay]; 
    [path removeAllPoints]; //(4) 
} 

- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event 
{ 
    [self touchesEnded:touches withEvent:event]; 
} 

- (void)drawBitmap // (3) 
{ 
    UIGraphicsBeginImageContextWithOptions(self.bounds.size, NO, 0.0); 
    [[UIColor blackColor] setStroke]; 
    if (!incrementalImage) // first draw; paint background white by ... 
    { 
     UIBezierPath *rectpath = [UIBezierPath bezierPathWithRect:self.bounds]; // enclosing bitmap by a rectangle defined by another UIBezierPath object 
     [[UIColor clearColor] setFill]; 
     [rectpath fill]; // filling it with white 
    } 
    [incrementalImage drawAtPoint:CGPointZero]; 
    [path stroke]; 
    incrementalImage = UIGraphicsGetImageFromCurrentImageContext(); 
    UIGraphicsEndImageContext(); 
} 
+0

समस्या आपकी 'drawBitmap' विधि में है, टिप्पणी' setStroke' पंक्ति 'और अंतर देखें। - शुभ लाभ –

उत्तर

16

आपके विचार में निम्नलिखित रखो - (आईडी) initWithFrame विधि:

self = [super initWithFrame:frame]; 
if (self) { 

    self.backgroundColor = [UIColor clearColor]; 

} 

return self; 

इस तरह आपके विचार उपवर्ग एक पारदर्शी पृष्ठभूमि होगा = कोई काला जब ड्राइंग बेजियर, CGContext ... विधियों या कुछ और का उपयोग कर।

संबंधित मुद्दे