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

  • Home
  • SEARCH
  • 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 8832221
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T08:28:47+00:00 2026-06-14T08:28:47+00:00

I have a program that when I tap the view a UITextField will appear.

  • 0

I have a program that when I tap the view a UITextField will appear. I also have an Undo-Button. I wanted to make a delete function when I double tap the UITextfield it can be deleted. Please Help Me.

Here is my code:

ViewController.h

#import <UIKit/UIKit.h>
#import <QuartzCore/QuartzCore.h>


@interface ViewController : UIViewController<UITextFieldDelegate, UIGestureRecognizerDelegate>
{

    NSMutableArray *textfieldform;
    UITextField *textField1;
    float   angle;
    CGFloat beginX;
    CGFloat beginY;
    IBOutlet UIView *blahBlah;
    CGPoint prevPanPoint;
    float prevPinchScale;
    float prevRotation;
}

@property (nonatomic, retain) NSMutableArray *textfieldform;

-(IBAction) undo;
- (IBAction)handleTap2:(UITapGestureRecognizer *)recognizer;

@end

ViewController.m

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

@synthesize text1, textfieldform;


- (void)viewDidLoad
{
    [super viewDidLoad];
    //textfieldform = [[NSMutableArray alloc] init];
    // Do any additional setup after loading the view, typically from a nib.
    textfieldform = [NSMutableArray arrayWithCapacity:0];
    angle = 180;

    UIPinchGestureRecognizer *pinchGesture = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(scaleImage:)];
    [blahBlah addGestureRecognizer:pinchGesture];

    UIRotationGestureRecognizer *rotationGesture = [[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(rotateImage:)];
    [blahBlah addGestureRecognizer:rotationGesture];

    UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(panGestureAction:)];
    [pan setMaximumNumberOfTouches:1];
    [pan setMinimumNumberOfTouches:1];
    [blahBlah addGestureRecognizer:rotationGesture];

    UITapGestureRecognizer *twoFingersTwoTaps = 
  [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(twoFingersTwoTaps)] ];
[twoFingersTwoTaps setNumberOfTapsRequired:2];
[twoFingersTwoTaps setNumberOfTouchesRequired:2];
[blahBlah addGestureRecognizer:twoFingersTwoTaps];

}


- (void)twoFingersTwoTaps {
  NSLog(@"Action: Delete text, two taps");
} 

-(void)panGestureAction:(UIPanGestureRecognizer *)pan {

    if (pan.state == UIGestureRecognizerStateBegan){
        prevPanPoint = [pan locationInView:blahBlah];
    }

    CGPoint curr = [pan locationInView:blahBlah];

    float diffx = curr.x - prevPanPoint.x;
    float diffy = curr.y - prevPanPoint.y;

    CGPoint centre = textField1.center;
    centre.x += diffx;
    centre.y += diffy;
    textField1.center = centre;

    prevPanPoint = curr;
}


-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer{
    return YES;
}

-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch{

    if([touch.view isKindOfClass:[UIView class]]) {
        return YES;
    }
    return NO;
}

- (void)scaleImage:(UIPinchGestureRecognizer *)recognizer
{
    if (recognizer.state == UIGestureRecognizerStateBegan)
        prevPinchScale = 1.0;

    float thisScale = 1 + (recognizer.scale-prevPinchScale);
    prevPinchScale = recognizer.scale;
    textField1.transform = CGAffineTransformScale(textField1.transform, thisScale, thisScale);
}

- (void)rotateImage:(UIRotationGestureRecognizer *)recognizer
{
    if([recognizer state] == UIGestureRecognizerStateEnded) {

            prevRotation = 0.0;
    } 

    float thisRotate = recognizer.rotation - prevRotation;
    prevRotation = recognizer.rotation;
    textField1.transform = CGAffineTransformRotate(textField1.transform, thisRotate);
}


-(IBAction)undo{
    UITextField *textFieldToRemove = [textfieldform lastObject];
    if (textFieldToRemove) {
        [textfieldform removeObject:textFieldToRemove];
        [textFieldToRemove removeFromSuperview];
    }
}


- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField{ 

    NSLog(@"textFieldShouldBeginEditing");
    return YES;
}
- (void)textFieldDidBeginEditing:(UITextField *)textField{           

    NSLog(@"textFieldDidBeginEditing");
    [textField1  setBackgroundColor:[UIColor colorWithRed:(248/255.0) green:(248/255.0) blue:(255/255.0) alpha:1.0]];
    textField1.borderStyle = UITextBorderStyleRoundedRect;
}
- (BOOL)textFieldShouldEndEditing:(UITextField *)textField{

    NSLog(@"textFieldShouldEndEditing");
    textField.backgroundColor = [UIColor clearColor];
    return YES;
}
- (void)textFieldDidEndEditing:(UITextField *)textField{

    NSLog(@"textFieldDidEndEditing");
    [textField1  setBackgroundColor:[UIColor clearColor]];
    textField1.borderStyle = UITextBorderStyleNone;
}
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{

    NSLog(@"textField:shouldChangeCharactersInRange:replacementString:");

    if ([string isEqualToString:@"#"]) {
        return NO;
    }
    else {
        return YES;
    }

}
- (BOOL)textFieldShouldClear:(UITextField *)textField{

    NSLog(@"textFieldShouldClear:");
    return YES;
}
- (BOOL)textFieldShouldReturn:(UITextField *)textField{

    NSLog(@"textFieldShouldReturn:");

    if (textField.tag == textfieldform.count) {
        textField1 = (UITextField *)[self.view viewWithTag:textfieldform.count];
        [textField1 becomeFirstResponder];
    }
    else {
        [textField resignFirstResponder];
    }

    return YES;
}

- (IBAction)handleTap2:(UITapGestureRecognizer *)recognizer{

    if (recognizer.state == UIGestureRecognizerStateEnded){
        CGPoint point = [recognizer locationInView:[self view]];
        textField1 = [[UITextField alloc] init];
        textField1.borderStyle = UITextBorderStyleLine;
        textField1.font = [UIFont systemFontOfSize:15];

        CGRect frame ;    
        frame.origin.x = point.x;
        frame.origin.y = point.y; 
        frame.size.width=300;
        frame.size.height=40;

        textField1.frame=frame;

        textField1.autocorrectionType = UITextAutocorrectionTypeNo;
        textField1.keyboardType = UIKeyboardTypeDefault;
        textField1.returnKeyType = UIReturnKeyDefault;
        textField1.clearButtonMode = UITextFieldViewModeWhileEditing;
        textField1.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;    
        textField1.delegate = self;
        textField1.tag = textfieldform.count;
        textField1.font = [UIFont fontWithName:@"Arial" size:30];
        [textfieldform addObject:textField1];
        [blahBlah addSubview:textField1];

        [textField1 addTarget:self action:@selector(wasDragged:withEvent:) forControlEvents:UIControlEventTouchDragInside];

    }

}

- (void)wasDragged:(UIButton *)button withEvent:(UIEvent *)event{
    // get the touch
    UITouch *touch = [[event touchesForView:textField1] anyObject];

    // get delta
    CGPoint previousLocation = [touch previousLocationInView:textField1];
    CGPoint location = [touch locationInView:textField1];
    CGFloat delta_x = location.x - previousLocation.x;
    CGFloat delta_y = location.y - previousLocation.y;

    // move button
    textField1.center = CGPointMake(textField1.center.x + delta_x,textField1.center.y + delta_y);

}

- (void)moveImage:(UIPanGestureRecognizer *)recognizer
{
    CGPoint newCenter = [recognizer translationInView:self.view];
    if([recognizer state] == UIGestureRecognizerStateBegan) {
        beginX = textField1.center.x;
        beginY = textField1.center.y;
    }
    newCenter = CGPointMake(beginX + newCenter.x, beginY + newCenter.y);
    [textField1 setCenter:newCenter];
}

- (void)viewDidUnload{
    [super viewDidUnload];
}

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

@end
  • 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-14T08:28:48+00:00Added an answer on June 14, 2026 at 8:28 am
    UITextField *textFieldToRemove = [textfieldform objectAtIndex:0];
                if (textFieldToRemove) {
                    NSLog(@"baaaaaaam! remove %i", textfieldform.count);
                    [textfieldform removeObject:textFieldToRemove];
                    [textFieldToRemove removeFromSuperview];
                } 
    

    I kinda Figured it out. 🙂

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

Sidebar

Related Questions

I have a program that will trap Ctrl + c , but it can
I have a program that convert image file to binary and also it converts
I have a program that will calculate the minimal area taken by fitting rectangles
I have a program that will get data from a fusion table, put it
I have a program that classifies text and would like to make it interactive
I have a program that will load an image from the hard disk. The
I have program that requires Python 3, but I develop Django and it uses
I have program that has a variable that should never change. However, somehow, it
I have program that runs fast enough. I want to see the number of
I have a program that gets a JSON from the server using getJSON and

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.