Events 为什么UIGraphicsGetCurrentContext不是';不对吗?
你能帮我吗?? “我的触摸”事件中的某些内容无法正常工作。 我的绘画区域有900 x 700px,不是完整的UIView。 在控制台中,显示错误:Events 为什么UIGraphicsGetCurrentContext不是';不对吗?,events,touch,cgcontext,Events,Touch,Cgcontext,你能帮我吗?? “我的触摸”事件中的某些内容无法正常工作。 我的绘画区域有900 x 700px,不是完整的UIView。 在控制台中,显示错误: CGContextAddLineToPoint: invalid context 0x0 CGContextMoveToPoint: invalid context 0x0 CGContextSetRGBStrokeColor: invalid context 0x0 CGContextSetLineWidth: invalid co
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;
在查看此链接之前,已回答此问题: 我已经对视图进行了子类化,并将代码放在drawRect方法中,它对我起了作用