Bất cứ ai cũng có ý tưởng tại sao CGContextFillPath sẽ không hoạt động trong đoạn mã dưới đây? Tôi đang sử dụng đoạn mã sau để vẽ lên UIImageView. Nó vuốt ve đường dẫn chính xác, nhưng bỏ qua CGContextFillPath.Bản vẽ dòng CGContext: CGContextFillPath không hoạt động?
UIGraphicsBeginImageContext(self.frame.size);
[drawingView.image drawInRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound);
CGContextSetLineWidth(UIGraphicsGetCurrentContext(), 5.0);
CGContextSetAllowsAntialiasing(UIGraphicsGetCurrentContext(), YES);
CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), 1.0, 0.0, 0.0, 1.0);
CGContextSetRGBFillColor(UIGraphicsGetCurrentContext(), 1.0, 0.0, 0.0, 1.0);
CGContextBeginPath(UIGraphicsGetCurrentContext());
CGContextMoveToPoint(UIGraphicsGetCurrentContext(), lastPoint.x, lastPoint.y);
CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), firstMovedTouch.x, firstMovedTouch.y);
CGContextStrokePath(UIGraphicsGetCurrentContext());
CGContextFillPath(UIGraphicsGetCurrentContext());
drawingView.image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
Ồ ... bạn nói đúng. Tôi đang sử dụng mã cho bản vẽ đường kẻ ghetto. Nhưng điều đó có ý nghĩa. Mã này được kích hoạt trên touchesMoved: và hoạt động tốt cho các bản vẽ đường, nhưng tôi sẽ phải lưu tất cả các điểm vào một mảng hoặc một thứ gì đó, để lấp đầy đường dẫn khi người dùng nhấc ngón tay lên. – RyJ