键盘到位时移动 UIScrollView

Move UIScrollView when keyboard comes into place(键盘到位时移动 UIScrollView)
本文介绍了键盘到位时移动 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

Hardware Volume buttons change in app volume(硬件音量按钮更改应用程序音量)
Cocos2d - How to check for Intersection between objects in different layers(Cocos2d - 如何检查不同层中对象之间的交集)
Resume game cocos2d(恢复游戏 cocos2d)
Highlight Read-Along Text (in a storybook type app for iPhone)(突出显示朗读文本(在 iPhone 的故事书类型应用程序中))
Cocos2D + Disabling only Retina iPad Graphics(Cocos2D + 仅禁用 Retina iPad 图形)
How to convert 32 bit PNG to RGB565?(如何将 32 位 PNG 转换为 RGB565?)