gpt4 book ai didi

iphone - 键盘到位时移动 UIScrollView

转载 作者:技术小花猫 更新时间:2023-10-29 10:06:36 25 4
gpt4 key购买 nike

[编辑:]问题已经解决。我没有在 UIBuilder 中正确链接我的委托(delegate)。代码很好!

我正在尝试在键盘出现时调整 ScrollView 的大小。我去了开发者文档并找到了这些信息。

http://developer.apple.com/library/ios/#documentation/StringsTextFonts/Conceptual/TextAndWebiPhoneOS/KeyboardManagement/KeyboardManagement.html#//apple_ref/doc/uid/TP40009542-CH5-SW1

在左侧“管理键盘”。

在文档中,它显示了一些代码来检测键盘的大小,然后调整 UIScrollView 的大小。我在函数 - (void)keyboardWasShown:(NSNotification*)aNotification 的代码中放置了一条 NSLog 消息,所以我看到该函数实际上正在被调用,但是当我尝试将 NSLog kbSize.height 的值始终设置为 0。

为什么苹果为此提供的代码不起作用?

- (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);
scrollView.contentInset = contentInsets;
scrollView.scrollIndicatorInsets = contentInsets;

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

最佳答案

您可能想尝试强烈推荐的“TPKeyboardAvoidingScrollView”,可从以下网址获得:https://github.com/michaeltyson/TPKeyboardAvoiding

像魅力一样工作......

关于iphone - 键盘到位时移动 UIScrollView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8590636/

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