Iphone 在ipad应用程序中绘制签名并将其转换为图像

Iphone 在ipad应用程序中绘制签名并将其转换为图像,iphone,ios,ipad,uiview,Iphone,Ios,Ipad,Uiview,我在ipad应用程序中绘制签名它工作正常,但问题是当它保存图像时,它也保存了签名的边框查看我只想保存绘图区域而不是完整的签名查看这是我的代码 signatureView=[[UIView alloc] initWithFrame:CGRectMake(100,100,800,500)]; signatureView.backgroundColor=[UIColor colorWithRed:242.0/255.f green:242/255.0f blue:242/255.0f alpha:

我在ipad应用程序中绘制签名它工作正常,但问题是当它保存图像时,它也保存了签名的边框查看我只想保存绘图区域而不是完整的签名查看这是我的代码

  signatureView=[[UIView alloc] initWithFrame:CGRectMake(100,100,800,500)];
signatureView.backgroundColor=[UIColor colorWithRed:242.0/255.f green:242/255.0f blue:242/255.0f alpha:1];


signatureView.layer.borderWidth =4;
signatureView.layer.borderColor = [UIColor colorWithRed:23.0/255.0f green:190/255.0f blue:210/255.0f alpha:1].CGColor;
signatureView.layer.cornerRadius=30;




[self.view addSubview:signatureView];



UIButton*OkButton = [UIButton buttonWithType:UIButtonTypeCustom];
   [OkButton setFrame:CGRectMake(320,448,118,49)];
    [OkButton setTitle:@"OK" forState:UIControlStateNormal];

[OkButton setImage:[UIImage imageNamed:@"okT.png"] forState:UIControlStateNormal];


   [OkButton addTarget:self action:@selector(onOKButtonClick) forControlEvents:UIControlEventTouchUpInside];
[signatureView addSubview:OkButton];

UILabel*textLabel=[[UILabel alloc] initWithFrame:CGRectMake(20,6,300,50)];

textLabel.font=[UIFont fontWithName:@"Helvetica-Bold" size:16];
textLabel.text=@"Use the touchscreen to sign here";
textLabel.backgroundColor=[UIColor clearColor];
textLabel.textColor=[UIColor grayColor];    
[signatureView addSubview:textLabel];


    drawScreen=[[MyLineDrawingView alloc]initWithFrame:CGRectMake(10,50,780,400)];
    [signatureView addSubview:drawScreen];
    [drawScreen release];


    //MyLineDrwaingView


   @interface MyLineDrawingView : UIView {

    UIBezierPath *myPath;
    UIColor *brushPattern;
   }

  @end


    #import "MyLineDrawingView.h"


    @implementation MyLineDrawingView

    - (id)initWithFrame:(CGRect)frame
  {

   self = [super initWithFrame:frame];
   if (self) {
    // Initialization code

    self.backgroundColor=[UIColor whiteColor];
    myPath=[[UIBezierPath alloc]init];
    myPath.lineCapStyle=kCGLineCapRound;
    myPath.miterLimit=0;
    myPath.lineWidth=10;
    //brushPattern=[UIColor redColor];
    brushPattern=[UIColor blackColor];

         }
        return self;
     }


    // Only override drawRect: if you perform custom drawing.
    // An empty implementation adversely affects performance during animation.
    - (void)drawRect:(CGRect)rect
   {

     [brushPattern setStroke];
     [myPath strokeWithBlendMode:kCGBlendModeNormal alpha:1.0];
     }

    #pragma mark - Touch Methods

   -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
  {

   UITouch *mytouch=[[touches allObjects] objectAtIndex:0];
   [myPath moveToPoint:[mytouch locationInView:self]];

   }

  -(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event

  {

   UITouch *mytouch=[[touches allObjects] objectAtIndex:0];
  [myPath addLineToPoint:[mytouch locationInView:self]];
   [self setNeedsDisplay];

  }


 -(void)onOKButtonClick {
 CGRect rect = [drawScreen bounds];   //use your signature view's Rect means Frame;
 UIGraphicsBeginImageContext(rect.size);
 CGContextRef context = UIGraphicsGetCurrentContext();
 [signatureView.layer renderInContext:context];   //this line is also important for you
 UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
    signImageView.image = img;
 }

此SO主题存在完全相同的问题(在iOS上绘制和保存签名):


如果有帮助,请尝试将您的问题标记为已解决。

因此此主题存在完全相同的问题(在iOS上绘制和保存签名):


如果有帮助,请尝试标记您的问题已解决。

我在代码中实现了以下工作:

.h文件添加UIgestureRecognitzerDelegate

米菲尔先生

-(void)scrollGesture:(UIGestureRecognizer *)sender
{

    CGPoint touchLocation = [sender locationInView:scrollView];

    NSLog(@"%d %d %d %d",touchLocation.y > signatureViewOne.frame.origin.y,touchLocation.y < signatureViewOne.frame.origin.y+80,touchLocation.x > 3, touchLocation.x < 308);
    if ((touchLocation.y > signatureViewOne.frame.origin.y && touchLocation.y < signatureViewOne.frame.origin.y+80) &&(touchLocation.x > 3 && touchLocation.x < 308))
    {
        NSLog(@"Signone found");
        scrollView.scrollEnabled = NO;

    }
    else

    if ((touchLocation.y > signatureViewTwo.frame.origin.y && touchLocation.y < signatureViewTwo.frame.origin.y+80) &&(touchLocation.x > 3 && touchLocation.x < 308))
    {
        NSLog(@"SignTwo found");
        scrollView.scrollEnabled = NO;

    }
    else
    {
        NSLog(@"not found");
        scrollView.scrollEnabled = YES;
        sender.enabled = YES;
    }


} 
-(无效)滚动手势:(UIgestureRecognitor*)发送方
{
CGPoint touchLocation=[sender locationInView:scrollView];
NSLog(@“%d%d%d%d”,touchLocation.y>SignatureWiOne.frame.origin.y,touchLocation.y3,touchLocation.x<308);
if((touchLocation.y>SignatureWiOne.frame.origin.y&&touchLocation.y3&&touchLocation.x<308))
{
NSLog(@“找到Signone”);
scrollView.scrollEnabled=否;
}
其他的
if((touchLocation.y>signatureViewTwo.frame.origin.y&&touchLocation.y3&&touchLocation.x<308))
{
NSLog(@“找到两个信号”);
scrollView.scrollEnabled=否;
}
其他的
{
NSLog(@“未找到”);
scrollView.scrollEnabled=是;
sender.enabled=是;
}
} 

我在我的代码中实现了以下工作:

.h文件添加UIgestureRecognitzerDelegate

米菲尔先生

-(void)scrollGesture:(UIGestureRecognizer *)sender
{

    CGPoint touchLocation = [sender locationInView:scrollView];

    NSLog(@"%d %d %d %d",touchLocation.y > signatureViewOne.frame.origin.y,touchLocation.y < signatureViewOne.frame.origin.y+80,touchLocation.x > 3, touchLocation.x < 308);
    if ((touchLocation.y > signatureViewOne.frame.origin.y && touchLocation.y < signatureViewOne.frame.origin.y+80) &&(touchLocation.x > 3 && touchLocation.x < 308))
    {
        NSLog(@"Signone found");
        scrollView.scrollEnabled = NO;

    }
    else

    if ((touchLocation.y > signatureViewTwo.frame.origin.y && touchLocation.y < signatureViewTwo.frame.origin.y+80) &&(touchLocation.x > 3 && touchLocation.x < 308))
    {
        NSLog(@"SignTwo found");
        scrollView.scrollEnabled = NO;

    }
    else
    {
        NSLog(@"not found");
        scrollView.scrollEnabled = YES;
        sender.enabled = YES;
    }


} 
-(无效)滚动手势:(UIgestureRecognitor*)发送方
{
CGPoint touchLocation=[sender locationInView:scrollView];
NSLog(@“%d%d%d%d”,touchLocation.y>SignatureWiOne.frame.origin.y,touchLocation.y3,touchLocation.x<308);
if((touchLocation.y>SignatureWiOne.frame.origin.y&&touchLocation.y3&&touchLocation.x<308))
{
NSLog(@“找到Signone”);
scrollView.scrollEnabled=否;
}
其他的
if((touchLocation.y>signatureViewTwo.frame.origin.y&&touchLocation.y3&&touchLocation.x<308))
{
NSLog(@“找到两个信号”);
scrollView.scrollEnabled=否;
}
其他的
{
NSLog(@“未找到”);
scrollView.scrollEnabled=是;
sender.enabled=是;
}
}