您的位置:首页 > 移动开发 > IOS开发

[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;

}];

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: