Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8865025
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T16:24:13+00:00 2026-06-14T16:24:13+00:00

Signature.h file #import <UIKit/UIKit.h> @interface Signature : UIViewController { CGPoint firstTouch; CGPoint lastTouch; UIColor

  • 0

Signature.h file

#import <UIKit/UIKit.h>

@interface Signature : UIViewController
{

    CGPoint firstTouch;
    CGPoint lastTouch;
    UIColor *pointColor;
    CGRect *points;
    int npoints;
    CGPoint location;
   // UIImageView *signatureImageView;
}
 @property CGPoint firstTouch;
@property CGPoint lastTouch;
@property (nonatomic, retain) UIColor *pointColor;
@property CGRect *points;
@property int npoints;

@property (retain, nonatomic) IBOutletCollection(UIImageView) NSArray *drawSign;
@property CGPoint location;

@property (retain, nonatomic) IBOutletCollection(UIImageView) NSArray *signatureImageView;
- (IBAction)savePressed:(id)sender;
- (IBAction)clearPressed:(id)sender;

@end

Signature.m

#import "Signature.h"

@interface Signature ()

@end

@implementation Signature
@synthesize drawSign;
@synthesize signatureImageView;
@synthesize firstTouch;
@synthesize lastTouch;
@synthesize  pointColor;
@synthesize  points;


- (id)initWithFrame:(CGRect)frame
{
    return self;
}


- (id)initWithCoder:(NSCoder *)coder
{
    if(self = [super initWithCoder:coder])
    {
        self.npoints = 0;
    }
    return self;
}

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    NSLog(@"initwithnibname");
    return self;
}

- (void)viewDidLoad
{
    NSLog(@"viewdidload");

    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
}

- (void)viewDidUnload
{
    NSLog(@"view did unload");

    [self setSignatureImageView:nil];
    [self setDrawSign:nil];
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    NSLog(@"touch has began");

    UITouch *touch = [touches anyObject];
    self.location = [touch locationInView:self.view];
}

- (void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
    NSLog(@"touches moves");

    UITouch *touch = [touches anyObject];
    CGPoint currentLocation = [touch locationInView:self.view];
   UIGraphicsBeginImageContext(self.view.frame.size);
    CGContextRef ctx = UIGraphicsGetCurrentContext();

  //[self.drawSign.image drawInRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
    CGContextSetLineCap(ctx, kCGLineCapRound);
    CGContextSetLineWidth(ctx, 5.0);
    CGContextSetRGBStrokeColor(ctx, 1.0, 0.0, 0.0, 1.0);
    CGContextBeginPath(ctx);
    CGContextMoveToPoint(ctx, location.x, location.y);
    NSLog(@"%f x is",location.x);
     NSLog(@"%f y is",location.y);
    CGContextAddLineToPoint(ctx, currentLocation.x, currentLocation.y);
    CGContextStrokePath(ctx);
   // self.image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();

    location = currentLocation;
}

- (void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
    NSLog(@"touches ended");

    UITouch *touch = [touches anyObject];
  CGPoint currentLocation = [touch locationInView:self.view];

   UIGraphicsBeginImageContext(self.view.frame.size);
    CGContextRef ctx = UIGraphicsGetCurrentContext();
    //[self.view.image drawInRect:CGRectMake(0, 0, self.frame.view.size.width, self.frame.view.size.height)];
    CGContextSetLineCap(ctx, kCGLineCapRound);
    CGContextSetLineWidth(ctx, 5.0);
    CGContextSetRGBStrokeColor(ctx, 1.0, 0.0, 0.0, 1.0);
    CGContextBeginPath(ctx);
    CGContextMoveToPoint(ctx, location.x, location.y);
   CGContextAddLineToPoint(ctx, currentLocation.x, currentLocation.y);
    CGContextStrokePath(ctx);
  //  self.image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();

    location = currentLocation;
} 

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

- (void)dealloc {
    [signatureImageView release];
    [super dealloc];
}
- (IBAction)savePressed:(id)sender {
    NSLog(@"save pressed");

}

- (IBAction)clearPressed:(id)sender {
    NSLog(@"cancel pressed");

}
@end

Please find the two files, related to my project. From One view I am coming to this view. Now I need to save whatever has been drawn on it by the user. I am able to fetch the co-ordinates but unable to draw them. I have tried several attempts but neither of them seems to be working.Please find them in the Signature.m file itself in commented way. Kindly point me my mistake and correct me.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T16:24:14+00:00Added an answer on June 14, 2026 at 4:24 pm

    I really dont understand your question but the reason this code is wrong is in the touches part.

    If you want to draw while you touch then you have to use the drawInRect method from the view you want to draw in.

    If you want to draw over an image to save or present it after the user releases it then you have to create an image context on the touchesBegan, then draw on it on the touchesMoved, and finally save the result in the touchesEnded.

    You can extract the result at the touchesEnded with

    UIImage *result = UIGraphicsGetImageFromCurrentImageContext();
    

    What your code is doing right now is, every time you move your finger you create a new canvas, draw on it and destroy it. When you lift your finger you create one more canvas draw on it and destroy it as well.

    But im pretty sure you want to move your finger and show the result directly in the screen. For that I really recommend you google for a tutorial but basically you have to: create an array of points in the touches begin, on the touches move you add points to this array and on the touches end you add the final point to the array. MEANWHILE on the view drawInRect your code has to continuously draw the points in this array.

    EDIT:

    ASSUMING you have a valid UIImage (blanc canvas already initialized) at the beginning in
    self.drawSign.image

    Try:

    - (void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
        NSLog(@"touches moves");
    
        UITouch *touch = [touches anyObject];
        CGPoint currentLocation = [touch locationInView:self.view];
       UIGraphicsBeginImageContext(self.view.frame.size);
        CGContextRef ctx = UIGraphicsGetCurrentContext();
    
        [self.drawSign.image drawInRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
        CGContextSetLineCap(ctx, kCGLineCapRound);
        CGContextSetLineWidth(ctx, 5.0);
        CGContextSetRGBStrokeColor(ctx, 1.0, 0.0, 0.0, 1.0);
        CGContextBeginPath(ctx);
        CGContextMoveToPoint(ctx, location.x, location.y);
        NSLog(@"%f x is",location.x);
         NSLog(@"%f y is",location.y);
        CGContextAddLineToPoint(ctx, currentLocation.x, currentLocation.y);
        CGContextStrokePath(ctx);
        self.drawSign.image = UIGraphicsGetImageFromCurrentImageContext();
        UIGraphicsEndImageContext();
    
        location = currentLocation;
    }
    
    - (void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
        NSLog(@"touches ended");
    
        UITouch *touch = [touches anyObject];
      CGPoint currentLocation = [touch locationInView:self.view];
    
       UIGraphicsBeginImageContext(self.view.frame.size);
        CGContextRef ctx = UIGraphicsGetCurrentContext();
        [self.drawSign.image drawInRect:CGRectMake(0, 0, self.frame.view.size.width, self.frame.view.size.height)];
        CGContextSetLineCap(ctx, kCGLineCapRound);
        CGContextSetLineWidth(ctx, 5.0);
        CGContextSetRGBStrokeColor(ctx, 1.0, 0.0, 0.0, 1.0);
        CGContextBeginPath(ctx);
        CGContextMoveToPoint(ctx, location.x, location.y);
       CGContextAddLineToPoint(ctx, currentLocation.x, currentLocation.y);
        CGContextStrokePath(ctx);
        self.drawSign.image = UIGraphicsGetImageFromCurrentImageContext();
        UIGraphicsEndImageContext();
    
        location = currentLocation;
    } 
    

    I am not sure if this will work, but even if it does it is a TERRIBLE WAY of doing it (performance wise).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a data file, a signature file (created by the GnuPG) and a
Can anybody tell me how to add signature in jar file. I have developed
I have a DER file with sha1RSA as the Signature Algorithm . I have
I could susscessfuly genearte pkcs7 signature using PEM(private key)file in Openssl. But, how do
The signature of the hashCode() method is public int hashCode(){ return x; } in
I have this function signature I have to match typedef int (*lua_CFunction) (lua_State *L);//target
I was under the impression that A D interface file contains only what an
I want to check a file has a valid IMAGE_DOS_SIGNATURE (MZ) function isMZ(FileName :
The signature of TraversableLike.flatMap is as follows: def flatMap[B, Th](f : (A) => Traversable[B])(implicit
The function signature on PHP.net for array_replace() says that the arrays will be passed

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.