Reputation: 224
I have the text field at the bottom of the screen. When the user taps it, the text field should animate up allowing room for the keyboard such as the iOS message app does. Anyway when this occurs, the animation is not happening correctly. Instead of going to where I specify (160, 410), It goes off the screen and right back on and then goes to where I specify. This causes it to look delayed and the keyboard goes up first. Here is my code:
- (void)viewDidLoad {
[super viewDidLoad];
textField1.delegate = self;
}
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
[UIView animateWithDuration:0.5 animations:^
{
[dock setCenter:CGPointMake(160, 410)];
}
completion:^(BOOL finished)
{
[dock setCenter:CGPointMake(160, 410)];
}];
return YES;
}
Upvotes: 0
Views: 58
Reputation: 161
You should really be using a transform, where in the same UIView.animateWithDuration block you say
dock.tranform = CGAffineTransformMakeTranslation(x, y)
Where x and y are the distance you want the doc to move.
See Here for more information.
Upvotes: 1
Reputation: 2052
Use the new syntax like this. Does it work?
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
[UIView animateWithDuration:0.4 animations:^
{
[dock setCenter:CGPointMake(160, 410)];
}
completion:^(BOOL finished)
{
//Implement completion method here.
}];
return YES;
}
Upvotes: 1