我只想在 ViewController 类型的同一个视图中的 2 个不同点之间画线。我已经编写了以下代码,但它没有显示线。请帮我解决这个问题。
- (void)drawRect:(CGRect)rect
{
[brushPattern setStroke];
[myPath strokeWithBlendMode:kCGBlendModeNormal alpha:1.0];
}
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *mytouch=[[touches allObjects] objectAtIndex:0];
// CGPoint *point=mytouch
[myPath moveToPoint:[mytouch locationInView:self.view]];
CGPoint pos = [mytouch locationInView: self.view];
NSLog(@"Position of touch: %.3f, %.3f", pos.x, pos.y);
}
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *mytouch=[[touches allObjects] objectAtIndex:0];
[myPath addLineToPoint:[mytouch locationInView:self.view]];
[self.view setNeedsDisplay];
}
-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *mytouch=[[touches allObjects] objectAtIndex:0];
CGPoint pos = [mytouch locationInView: self.view];
NSLog(@"Position of touch: %.3f, %.3f", pos.x, pos.y);
}