我正在使用3.2 sdk开发一款iPad应用程序.我正在处理获取键盘大小的问题,以防止文本字段隐藏在键盘后面.

I'm getting a Warning in Xcode -> UIKeyboardBoundsUserInfoKey is deprecated what should I use instead not to get this warning?

推荐答案

我使用了之前提供的解决方案,但仍然存在问题.以下是我的 idea :

    - (void)keyboardWillShow:(NSNotification *)aNotification {
    [self moveTextViewForKeyboard:aNotification up:YES];
}

    - (void)keyboardWillHide:(NSNotification *)aNotification {
        [self moveTextViewForKeyboard:aNotification up:NO]; 
    }

- (void) moveTextViewForKeyboard:(NSNotification*)aNotification up: (BOOL) up{
NSDictionary* userInfo = [aNotification userInfo];

// Get animation info from userInfo
NSTimeInterval animationDuration;
UIViewAnimationCurve animationCurve;

CGRect keyboardEndFrame;

[[userInfo objectForKey:UIKeyboardAnimationCurveUserInfoKey] getValue:&animationCurve];
[[userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey] getValue:&animationDuration];


[[userInfo objectForKey:UIKeyboardFrameEndUserInfoKey] getValue:&keyboardEndFrame];


// Animate up or down
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:animationDuration];
[UIView setAnimationCurve:animationCurve];

CGRect newFrame = textView.frame;
CGRect keyboardFrame = [self.view convertRect:keyboardEndFrame toView:nil];

newFrame.origin.y -= keyboardFrame.size.height * (up? 1 : -1);
textView.frame = newFrame;

[UIView commitAnimations];
}

Objective-c相关问答推荐

恢复 iOS7 之前的 UINavigationController pushViewController 动画

NSViewController 中的 viewDidLoad?

如何通过仅更改高度而不更改宽度来调整 UILabel 的大小?

是否可以 suppress Xcode 4 静态分析器警告?

如何使用格式化占位符本地化字符串?

当前时间是 HH:MM:SS am/pm 格式吗?

单元测试私有方法 - 目标 C

UITableView 无限滚动

如何在目标 C 中创建单例类

静态 NSString 使用与内联 NSString 常量

iOS 中 textField 上的Electron邮件验证

如何删除 xcode 5 中的旧配置文件?

如何测试生产推送通知?

警告的含义在演示过程中!

首次提交应用内购买以供审核

将 HTTP 标头添加到 NSURLRequest

将块存储在数组中

@dynamic 在 Objective-C 中做了什么?

NSString 中子字符串的出现次数?

将浮点数四舍五入到objective C中的下一个整数?