有没有办法将简单 UIView 中的某些文本字段向上移动,以便它们无法隐藏在键盘后面。?不使用UIScrollView是否可以
最佳答案
应该可以调整 UITextField 所在 View 的框架位置。查看此代码:
http://iphoneincubator.com/blog/tag/uitextfield
- (void)textFieldDidBeginEditing:(UITextField *)textField {
[self scrollViewToCenterOfScreen:textField];
}
- (void)scrollViewToCenterOfScreen:(UIView *)theView {
CGFloat viewCenterY = theView.center.y;
CGRect applicationFrame = [[UIScreen mainScreen] applicationFrame];
CGFloat availableHeight = applicationFrame.size.height - keyboardBounds.size.height; // Remove area covered by keyboard
CGFloat y = viewCenterY - availableHeight / 2.0;
if (y < 0) {
y = 0;
}
scrollView.contentSize = CGSizeMake(applicationFrame.size.width, applicationFrame.size.height + keyboardBounds.size.height);
[scrollView setContentOffset:CGPointMake(0, y) animated:YES];
}
关于iphone - 在没有 ScrollView 的简单 UIVIew 中,当 UITextField 出现键盘时调整界面?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/909562/