gpt4 book ai didi

ios - 在 iOS8 上显示键盘时停用 View moveUp

转载 作者:行者123 更新时间:2023-11-29 02:26:23 25 4
gpt4 key购买 nike

在我的应用程序中,我有一个注册表单,其中包含一些文本字段(电子邮件、密码等...),当我开始在这些文本字段中的某处键入内容时(显示键盘),我的 View 向上移动,然后我'我看不到我的文本字段中输入的内容。

此问题仅在 iOS8 上出现。

如果有人知道如何阻止此操作系统功能,我将不胜感激。

问候。

最佳答案

这是我用于管理与键盘出现和消失相关的问题的代码。

- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
[self registerForKeyboardNotifications];
}

- (void)registerForKeyboardNotifications
{
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardWasShown:)
name:UIKeyboardDidShowNotification object:nil];

[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardWillBeHidden:)
name:UIKeyboardWillHideNotification object:nil];

}

#pragma mark - Keyboard Delegate
// Called when the UIKeyboardDidShowNotification is sent.
- (void)keyboardWasShown:(NSNotification*)aNotification
{
NSDictionary* info = [aNotification userInfo];
CGSize kbSize = [[info objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size;

//to overcome the bug with keyboard height for os7 and earlier
if (![UIDeviceHardware isOS8Device]) {
CGRect kbRect = [[info objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue];
kbRect = [self.view convertRect:kbRect fromView:nil];
kbSize = kbRect.size;
}

UIEdgeInsets contentInsets = UIEdgeInsetsMake(0.0, 0.0, kbSize.height, 0.0);
_scrollView.contentInset = contentInsets;
_scrollView.scrollIndicatorInsets = contentInsets;

// If active text field is hidden by keyboard, scroll it so it's visible
// Your app might not need or want this behavior.
CGRect aRect = self.view.frame;
aRect.size.height -= kbSize.height;
if (!CGRectContainsPoint(aRect, activeField.frame.origin) ) {
[_scrollView scrollRectToVisible:activeField.frame animated:YES];
}
}

// Called when the UIKeyboardWillHideNotification is sent
- (void)keyboardWillBeHidden:(NSNotification*)aNotification
{
UIEdgeInsets contentInsets = UIEdgeInsetsZero;
_scrollView.contentInset = contentInsets;
_scrollView.scrollIndicatorInsets = contentInsets;
}

您可以从 UITextfield Delegate 中选择 activeField

关于ios - 在 iOS8 上显示键盘时停用 View moveUp,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27480912/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com