Right now I have the basic code to move the text box above the keyboard when starting editing. However, the size of the text field depends on the device and orientation. So, I wrote a rough way to do this, which does not always remain right above the keyboard, but instead grows when you rotate it, and therefore it does not look as professional as we would like.
The main point of my question is that there is logic to get the keyboard size based on the device and the orientation and use of this value automatically and, I hope, faster than that.
If this is the best way, please let me know. Otherwise, please indicate input. Here is the code I have. (This is just a move code, not a down code to prevent too much space).
- (void)textFieldDidBeginEditing:(UITextField *)textField {
NSString *deviceType = [[UIDevice currentDevice] model];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDelegate:self];
[UIView setAnimationDuration:0.4];
[UIView setAnimationBeginsFromCurrentState:YES];
if ([deviceType isEqualToString:@"iPhone"]) {
googleBar.frame = CGRectMake(googleBar.frame.origin.x - 62.0, (googleBar.frame.origin.y - 210.0), googleBar.frame.size.width + 120.0, googleBar.frame.size.height);
} else if ([deviceType isEqualToString:@"iPad"]) {
googleBar.frame = CGRectMake(googleBar.frame.origin.x - 62.0, (googleBar.frame.origin.y - 320.0), googleBar.frame.size.width + 120.0, googleBar.frame.size.height);
} else if ([deviceType isEqualToString:@"iPod touch"]) {
googleBar.frame = CGRectMake(googleBar.frame.origin.x - 62.0, (googleBar.frame.origin.y - 210.0), googleBar.frame.size.width + 120.0, googleBar.frame.size.height);
}
[UIView commitAnimations];
}
source
share