Titouan de Bailleul
Titouan de Bailleul

Reputation: 12959

Detect when editing ends on one uitextfield but starts on another

I just created two functions, slideAuthViewUp and slideAuthViewDown that are called when you enter the login or password UITextfield. It is useful in landscape mode to see the whole authentication form.

These are called like below:

[passwordTextField addTarget:self action:@selector(slideAuthFormUp) forControlEvents:UIControlEventEditingDidBegin];
[passwordTextField addTarget:self action:@selector(slideAuthFormDown) forControlEvents:UIControlEventEditingDidEnd];

[loginTextField addTarget:self action:@selector(slideAuthFormUp) forControlEvents:UIControlEventEditingDidBegin];
[loginTextField addTarget:self action:@selector(slideAuthFormDown) forControlEvents:UIControlEventEditingDidEnd];

Now, the problem is when I click on the password textfield the slideAuthFromDown is called by the login textfield and then the slideAuthFormUp is called by the password textfield. So the authentication form goes down and up in a really short time which is not what I want. I would like this form to stay up during this short time.

Does anybody know how to do that?

Upvotes: 1

Views: 362

Answers (2)

medampudi
medampudi

Reputation: 399

hmm... have a look at this example given in the website here the Appcodeblog. The code is from there.. I hold no responsibility for the code i am just referencing my evernote clip from that website. which has everything at one place. ... starting from tutorial 1 to 3.

Upvotes: 0

Simon Lee
Simon Lee

Reputation: 22334

You need to perform the slide down after a short delay, and if a slide up happens within that time, cancel the scheduled selector. So...have an intermediary method...

- (void)delayedSlideDown {
  [self performSelector:@selector(slideAuthFormDown) withObject:nil afterDelay:0.2];
}

Then use...

[passwordTextField addTarget:self action:@selector(delayedSlideDown) forControlEvents:UIControlEventEditingDidEnd];

And finally add the following line to slideAuthFormUp....

[NSObject cancelPreviousPerformRequestsWithTarget:self];

You may need to play with the 0.2 delay...

Upvotes: 1

Related Questions