[ios] 适应键盘高度变化
2014-01-24 08:34
344 查看
- (void)regNotification
{
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillChangeFrame:) name:UIKeyboardWillChangeFrameNotification object:nil];
}
- (void)unregNotification
{
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillChangeFrameNotification object:nil];
}
#pragma mark - notification handler
- (void)keyboardWillChangeFrame:(NSNotification *)notification
{
NSDictionary *info = [notification userInfo];
CGFloat duration = [[info objectForKey:UIKeyboardAnimationDurationUserInfoKey] floatValue];
CGRect beginKeyboardRect = [[info objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue];
CGRect endKeyboardRect = [[info objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue];
CGFloat yOffset = endKeyboardRect.origin.y - beginKeyboardRect.origin.y;
CGRect inputFieldRect = self.inputTextField.frame;
CGRect moreBtnRect = self.moreInputTypeBtn.frame;
inputFieldRect.origin.y += yOffset;
moreBtnRect.origin.y += yOffset;
[UIView animateWithDuration:duration animations:^{
self.inputTextField.frame = inputFieldRect;
self.moreInputTypeBtn.frame = moreBtnRect;
}];
}
{
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillChangeFrame:) name:UIKeyboardWillChangeFrameNotification object:nil];
}
- (void)unregNotification
{
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillChangeFrameNotification object:nil];
}
#pragma mark - notification handler
- (void)keyboardWillChangeFrame:(NSNotification *)notification
{
NSDictionary *info = [notification userInfo];
CGFloat duration = [[info objectForKey:UIKeyboardAnimationDurationUserInfoKey] floatValue];
CGRect beginKeyboardRect = [[info objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue];
CGRect endKeyboardRect = [[info objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue];
CGFloat yOffset = endKeyboardRect.origin.y - beginKeyboardRect.origin.y;
CGRect inputFieldRect = self.inputTextField.frame;
CGRect moreBtnRect = self.moreInputTypeBtn.frame;
inputFieldRect.origin.y += yOffset;
moreBtnRect.origin.y += yOffset;
[UIView animateWithDuration:duration animations:^{
self.inputTextField.frame = inputFieldRect;
self.moreInputTypeBtn.frame = moreBtnRect;
}];
}
相关文章推荐
- 如何完美适应iOS中的键盘高度变化
- 完美适应iOS中的键盘高度变化
- 完美适应iOS中的键盘高度变化
- 适应iOS中的键盘高度变化
- [ios] 适应键盘高度变化
- 完美适应iOS中的键盘高度变化
- 适应ios中键盘高度的变化
- 状态键盘完美适应iOS中的键盘高度变化
- iOS开发之监听键盘高度的变化
- 【代码笔记】iOS-屏幕根据键盘自动的变化高度
- iOS开发中的键盘高度变化处理
- 【代码笔记】iOS-屏幕根据键盘自动的变化高度
- iOS开发之监听键盘高度的变化
- iOS开发中的键盘高度变化处理
- iOS屏幕根据键盘自动变化高度
- iOS开发之监听键盘高度的变化 分类: ios技术 2015-04-21 12:04 233人阅读 评论(0) 收藏
- iOS开发之监听键盘高度的变化
- iOS开发中的键盘高度变化处理
- iOS开发之监听键盘高度的变化
- iOS开发中的键盘高度变化处理