html5中文学习网

您的位置: 首页 > ios » 正文

如何完美适应iOS中的键盘高度变化_IOS开发

[ ] 已经帮助:人解决问题

 #pragma mark - reg & unreg notification3zVHTML5中文学习网 - HTML5先行者学习网

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

通过获取键盘消息的开始状态、结束状态,以及变化周期,可以计算出具体的Y偏移,从而在相同时间里做相同偏移量。 3zVHTML5中文学习网 - HTML5先行者学习网

(责任编辑:)
推荐书籍
推荐资讯
关于HTML5先行者 - 联系我们 - 广告服务 - 友情链接 - 网站地图 - 版权声明 - 人才招聘 - 帮助