【发布时间】:2012-02-03 20:45:46
【问题描述】:
现在,我有一些基本代码可以在您开始编辑时移动键盘上方的文本字段。但是,文本字段的大小因设备和方向而异。所以,我写了一个粗略的方法,它不会一直保持在键盘上方,而是在你旋转它时会进一步上升,所以它看起来不像我想要的那样专业。
我的问题的基本意义是,是否有一种逻辑可以根据设备和方向获取键盘的大小,并自动使用该值,希望比这更快。
如果这是最好的方法,请告诉我。否则,请提供输入。这是我拥有的代码。 (这里只是上移代码,不是下移代码,以免占用太多空间)
- (void)textFieldDidBeginEditing:(UITextField *)textField {
//Get Device Type
NSString *deviceType = [[UIDevice currentDevice] model];
//Animate Text Field
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDelegate:self];
[UIView setAnimationDuration:0.4];
[UIView setAnimationBeginsFromCurrentState:YES];
if ([deviceType isEqualToString:@"iPhone"]) {
//Size For 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"]) {
//Size for 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"]) {
//Size For 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];
}
【问题讨论】:
标签: objective-c ios xcode uitextfield