gpt4 book ai didi

ios - 键盘关闭时 ScrollView 不向下滚动

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:04:48 25 4
gpt4 key购买 nike

我使用了关于移动键盘下方内容的苹果指南

Guide here

当键盘打开时向上滚动效果很好,但当键盘关闭时它不会向下滚动, ScrollView 的顶部被截断。

我的代码

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

UIEdgeInsets contentInsets = UIEdgeInsetsMake(0.0, 0.0, kbSize.height, 0.0);
_myScrollView.contentInset = contentInsets;
_myScrollView.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) ) {
[self.myScrollView scrollRectToVisible:activeField.frame animated:YES];
}
}

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

最佳答案

这是我在键盘退出时使用的代码。我在使用您的原始代码时遇到了麻烦,因为它似乎不想在 iOS 7 中工作。

-(void) keyboardWillHide:(NSNotification *)note
{
// Get the keyboard size
CGRect keyboardBounds;
[[note.userInfo valueForKey:UIKeyboardFrameBeginUserInfoKey] getValue: &keyboardBounds];

CGRect frame = self.scrollView.frame;

[UIView beginAnimations:nil context:NULL];
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView setAnimationDuration:0.3f];

//add keyboard size to current scrollview frame
frame.size.height += keyboardBounds.size.height;

//apply frame to scrollview
self.scrollView.frame = frame;

[UIView commitAnimations];
}

关于ios - 键盘关闭时 ScrollView 不向下滚动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24666229/

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