我正在尝试开发一个绘画应用程序,它允许用户通过选择不同颜色的画笔来绘制/绘制图像。我试图通过继承uiimageview来实现它并覆盖以下方法:
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [touches anyObject];
lastPoint = [touch locationInView:self];
// lastPoint.y -=20;// only if signature goes bottom of the screen
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [touches anyObject];
CGPoint currentPoint = [touch locationInView:self];
// currentPoint.y -=20; // only if signature goes bottom of the screen
UIGraphicsBeginImageContext(self.frame.size);
CGContextRef currentContext = UIGraphicsGetCurrentContext();
[self.image drawInRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
CGContextSetLineCap(currentContext, kCGLineCapRound);
CGContextSetLineWidth(currentContext, 15.0);
CGContextSetRGBStrokeColor(currentContext, 1.0, 0.0, 0.0, 1.0);
CGContextBeginPath(currentContext);
CGContextMoveToPoint(currentContext, lastPoint.x, lastPoint.y);
CGContextAddLineToPoint(currentContext, currentPoint.x, currentPoint.y);
CGContextStrokePath(currentContext);
self.image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
lastPoint = currentPoint;
}
但问题在于,如果用户绘制图像的边界线,则颜色会隐藏边界线。即使用户也在边界线上绘制,我也需要使边界线可见。是否可以这样做或者我是否需要继续使用任何openGL技术。请分享您的意见..
提前致谢..
答案 0 :(得分:0)
您可以创建仅包含边框的UIView
子类,并将其添加到当前视图之上。
您只需在pointInside: withEvent:
方法中返回否,即可将触摸转移到其下方的视图中。
- (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event{
return NO;
}