1
你能幫助我嗎? 觸摸事件中的某些內容無法正常工作。 我的繪畫區域有900 x 700px,不是完整的UIView。 在控制檯錯誤告訴我:爲什麼UIGraphicsGetCurrentContext不正確?
CGContextAddLineToPoint: invalid context 0x0
CGContextMoveToPoint: invalid context 0x0
CGContextSetRGBStrokeColor: invalid context 0x0
CGContextSetLineWidth: invalid context 0x0......
.......
.......
爲什麼UIGraphicsGetCurrentContext是不正確的?
如何解決這個錯誤
我的代碼:
- (void)**touchesMoved**:(NSSet *)touches withEvent:(UIEvent *)event {
mouseSwiped = YES;
UITouch *touch = [touches anyObject];
CGPoint currentPoint = [touch locationInView:self.tempDrawImage];
UIGraphicsBeginImageContext(self.tempDrawImage.frame.size);
[self.tempDrawImage.image drawInRect:CGRectMake(0, 0, self.tempDrawImage.frame.size.width, self.tempDrawImage.frame.size.height)];
CGContextMoveToPoint(UIGraphicsGetCurrentContext(), lastPoint.x, lastPoint.y);
CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), currentPoint.x, currentPoint.y);
CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound);
CGContextSetLineWidth(UIGraphicsGetCurrentContext(), brush);
CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), red, green, blue, 1.0);
CGContextSetBlendMode(UIGraphicsGetCurrentContext(),kCGBlendModeNormal);
CGContextStrokePath(UIGraphicsGetCurrentContext());
self.tempDrawImage.image = UIGraphicsGetImageFromCurrentImageContext();
[self.tempDrawImage setAlpha:opacity];
UIGraphicsEndImageContext();
lastPoint = currentPoint;