NO IMAGE

PJRSignatureView

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
if ([lblSignature superview]){//檢查父檢視
[lblSignature removeFromSuperview];//<span style="font-family: Arial; font-size: 14px; line-height: 26px;">把當前view從它的父view和視窗中移除,同時也把它從響應事件操作的響應者鏈中移除</span>
}//開始書寫時使提示標籤消失的方法
control = 0;
UITouch *touch = [touches anyObject];//返回觸控物件集合
points[0] = [touch locationInView:self];//返回當前觸點座標
CGPoint startPoint = points[0];
CGPoint endPoint = CGPointMake(startPoint.x   1.5, startPoint.y
2);
[beizerPath moveToPoint:startPoint];//繪製起點
[beizerPath addLineToPoint:endPoint];//終點
}

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [touches anyObject];
CGPoint touchPoint = [touch locationInView:self];
control  ;
points[control] = touchPoint;
if (control == 4)//籌4個點繪製一次
{
points[3] = CGPointMake((points[2].x   points[4].x)/2.0, (points[2].y   points[4].y)/2.0);
[beizerPath moveToPoint:points[0]];//起點
[beizerPath addCurveToPoint:points[3] controlPoint1:points[1] controlPoint2:points[2]];//繪製貝塞爾路徑
[self setNeedsDisplay];//繪製
points[0] = points[3];
points[1] = points[4];
control = 1;
}
}

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
[self drawBitmapImage];//繪製簽名圖片
[self setNeedsDisplay];
[beizerPath removeAllPoints];//刪除所有點,有效的刪除路徑
control = 0;
}

- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event
{
[self touchesEnded:touches withEvent:event];
}

- (void)drawBitmapImage
{
UIGraphicsBeginImageContextWithOptions(self.bounds.size, YES, 0.0);//根據指定選項建立點陣圖圖形上下文
if (!incrImage)
{
UIBezierPath *rectpath = [UIBezierPath bezierPathWithRect:self.bounds];//建立一個矩形路徑
[[UIColor whiteColor] setFill];
[rectpath fill];
}
[incrImage drawAtPoint:CGPointZero];
//Set final color for drawing
UIColor *strokeColor = FINAL_COLOR;
[strokeColor setStroke];
[beizerPath stroke];
incrImage = UIGraphicsGetImageFromCurrentImageContext();//根據圖形上下文返回一個影象
UIGraphicsEndImageContext();//關閉圖形上下文
}

- (void)clearSignature//清空
{
incrImage = nil;
[self setNeedsDisplay];
}

- (UIImage *)getSignatureImage {
if([lblSignature superview]){
return nil;
}
UIGraphicsBeginImageContextWithOptions(self.bounds.size, NO, [UIScreen mainScreen].scale);
[self drawViewHierarchyInRect:self.bounds afterScreenUpdates:YES];//根據圖形上下文繪製快照,利用view層次結構並將其繪製到當前的上下文中
UIImage *signatureImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return signatureImage;
}