Ich frage mich, wie man ein CGRect auf ein UIImageView zeichnet. Hier ist der Code, den ich habe, aber es scheint nicht zu funktionieren. Irgendwelche Vorschläge? touch1 und touch2 sind beide CGPoints und Punkt ist ein CGRect.Zeichnen eines CGRect durch Berühren von
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [touches anyObject];
touch1 = [touch locationInView:self];
touch2 = [touch locationInView:self];
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [touches anyObject];
touch2 = [touch locationInView:self];
point = CGRectMake(touch2.x, touch2.y, 50, 50);
[self setNeedsDisplay];
}
- (void) drawRect:(CGRect)rect {
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetLineWidth(context, 2.0);
CGContextSetStrokeColorWithColor(context, [UIColor blackColor].CGColor);
CGContextSetFillColorWithColor(context, pointColor.CGColor);
CGContextAddEllipseInRect(context, point);
CGContextDrawPath(context, kCGPathFillStroke);
}
versuchen Sie ein Rechteck oder einen Kreis zu zeichnen? Du hast in deinen Kommentaren 'ein CGRect' gesagt, aber im Code steht CGContextAddEllipseInRect – slf
Entschuldigung dafür, dass ich nicht spezifiziert habe ... an dieser Stelle versuche ich nur etwas zu bekommen, das allgemein auf dem Bildschirm gezeichnet werden kann. Ich habe eine Klasse, die eine Unterklasse eines UIViewController ist, der das ImageView ein tatsächliches Bild anzeigt. Ich möchte nur auf dieses Bild zurückgreifen können. – Brandon