美文网首页
完美适配iOS中得 键盘高度变化

完美适配iOS中得 键盘高度变化

作者: 渣渣程序猿爱次次大餐 | 来源:发表于2015-11-17 16:56 被阅读4987次

#pragma mark - reg & unreg notification

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

}];

}

相关文章

网友评论

      本文标题:完美适配iOS中得 键盘高度变化

      本文链接:https://www.haomeiwen.com/subject/unzkhttx.html