Move UIScrollView when keyboard comes into place(键盘到位时移动 UIScrollView)
问题描述
问题已解决.我没有在 UIBuilder
中正确链接我的代表.代码很好!
The problem has been solved. I did not have my delegates linked properly in UIBuilder
. Code is good!
我正在尝试在键盘出现时调整滚动视图的大小.我去了开发者文档并找到了这些信息.
I am trying to resize a scrollview when the keyboard appears. I went to the developer docs and found this information.
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.
In the documentation it shows a bit of code to detect the size of the keyboard and then to resize a UIScrollView
. I have placed an NSLog
message in the code for function - (void)keyboardWasShown:(NSNotification*)aNotification
so I see that the function is actually being called, but when I try to to NSLog
the kbSize
.height it is always valued at 0.
为什么苹果为此目的提供的代码不起作用?
Why does the code that apple provide for this purpose not work?
- (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
You may want to try the highly recommended "TPKeyboardAvoidingScrollView", available from: https://github.com/michaeltyson/TPKeyboardAvoiding
像魅力一样工作......
Works like a charm...
这篇关于键盘到位时移动 UIScrollView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:键盘到位时移动 UIScrollView
基础教程推荐
- 如何在 UIImageView 中异步加载图像? 2022-01-01
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01
- android 应用程序已发布,但在 google play 中找不到 2022-01-01
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01
- Android:对话框关闭而不调用关闭 2022-01-01
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01