iphone绘画应用程序
我正在尝试开发一个绘画应用程序,允许用户通过选择不同颜色的画笔在图像上绘制/绘画。我尝试通过将uiimageview子类化并覆盖以下方法来实现这一点:iphone绘画应用程序,iphone,ios4,Iphone,Ios4,我正在尝试开发一个绘画应用程序,允许用户通过选择不同颜色的画笔在图像上绘制/绘画。我尝试通过将uiimageview子类化并覆盖以下方法来实现这一点: - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { UITouch *touch = [touches anyObject]; lastPoint = [touch locationInView:self]; // lastPoin
- (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技术。请分享您的评论
提前感谢。您可以创建一个只包含边框的
UIView
子类,并将其添加到当前视图的顶部。
您只需在pointInside:withEvent:
方法中返回No即可将触摸传递到其下方的视图
- (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event{
return NO;
}
我不太确定这是否是你想要的,但是在这个链接中,我们解释了CGContextClip(),它将绘图限制在一个特定的区域