Code cracker
Code cracker

Reputation: 3166

UITextField cursor animated top to down then text also being animated

I am working registration form in iOS application. There several textfields such as name,email,city etc. when the textfield started editing cursor appearing like animated. Cursor slowly coming from top to down after typing the letter its moving from left to right slowly.I need to stop this unwanted animation. I am using TPKeyboardAvoiding scrollview to scroll the view when keyboard popup. I checked it without TPKeyboardAvoiding but same thing happening.enter image description here

Upvotes: 2

Views: 1072

Answers (3)

Faisal Ali
Faisal Ali

Reputation: 1135

I encountered same issue, after debugging I found that this weird animation is happening because of

- (void)TPKeyboardAvoiding_keyboardWillShow:(NSNotification*)notification {
    //...
    [self layoutIfNeeded];
    //...
}

- (void)TPKeyboardAvoiding_keyboardWillHide:(NSNotification*)notification {
    //...
    [self layoutIfNeeded];
    //...
}

I am able to fix this issue by removing [self layoutIfNeeded]; method call. I don't know if this solution affects anything else.

Upvotes: 2

Eric Baker
Eric Baker

Reputation: 11

Call superview.layoutIfNeeded() (or self.view.layoutIfNeeded(), depending on your code context) before you begin changing any animatable properties in the view. This allows the superview to finish its own layout changes (if any) before you make your own layout changes and commit your animations. (This may be difficult to track down if an external library is applying its own animations.)

Upvotes: 0

Robert J. Clegg
Robert J. Clegg

Reputation: 7360

I suspect the animation comes from the TPKeyboardAvoiding library. I also have the same screen in my app (Registration) and use the same library. However I put my textfields inside a custom UITableViewCell and have a UITableView for the registration. This way there is less code and its cleaner. I disable scrolling on the UITableView so that the UIScrollView will receive the touches correctly.

I'd suggest doing it that way.

Upvotes: 1

Related Questions