ios – iPad上的UIModalPresentationFormSheet.键盘出现时如何调整UITextView高度

ios – iPad上的UIModalPresentationFormSheet.键盘出现时如何调整UITextView高度,第1张

概述UITextView是模态控制器视图的子视图.当键盘出现时,我需要降低UITextView高度,以便UITextView的底部边框y坐标等于键盘的顶部y坐标. 我想要键盘高度 CGRect frameBegin = [[notification.userInfo objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue] ;CGRect UITextVIEw是模态控制器视图的子视图.当键盘出现时,我需要降低UITextVIEw高度,以便UITextVIEw的底部边框y坐标等于键盘的顶部y坐标.
我想要键盘高度
CGRect frameBegin = [[notification.userInfo objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue] ;CGRect frameEnd = [[notification.userInfo objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue];CGRect resultBegin = [self.vIEw convertRect:frameBegin fromVIEw:nil];CGRect resultEnd = [self.vIEw convertRect:frameEnd fromVIEw:nil];CGfloat kbdHeight = resultBegin.origin.y  - resultEnd.origin.y;

问题是当键盘出现时,此模态视图会跳起来.在这种情况下如何计算键盘的顶部边框坐标?

解决方法 你可以这样做:
1. Register for keyboard notifications:[[NSNotificationCenter defaultCenter] addobserver:self                                         selector:@selector(myTextVIEwHeightAdjustMethod:)                                             name:UIKeyboarDWillShowNotification                                           object:nil];[[NSNotificationCenter defaultCenter] addobserver:self                                         selector:@selector(myTextVIEwHeightAdjustMethod:)                                             name:UIKeyboardDIDShowNotification                                           object:nil];2. Calculate intersection and adjust textVIEw height with the bottom constraint    - (voID)myTextVIEwHeightAdjustMethod:(NSNotification *)notification    {        NSDictionary *userInfo = [notification userInfo];        CGRect keyboardFinalFrame = [[userInfo emf_ObjectOrNilForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue];        CGPoint keyboardOriginInVIEw = [self.vIEw convertPoint:keyboardFinalFrame.origin fromVIEw:nil];             CGfloat intersectionY = CGRectGetMaxY(self.vIEw.frame) - keyboardOriginInVIEw.y;             if (intersectionY >= 0)             {                 self.textVIEwBottomConstraint.constant = intersectionY + originalTextVIEwBottomConstraint;                 [self.textVIEw setNeedsLayout];    }

请记得取消注册通知.

总结

以上是内存溢出为你收集整理的ios – iPad上的UIModalPresentationFormSheet.键盘出现时如何调整UITextView高度全部内容,希望文章能够帮你解决ios – iPad上的UIModalPresentationFormSheet.键盘出现时如何调整UITextView高度所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1100058.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-28
下一篇 2022-05-28

发表评论

登录后才能评论

评论列表(0条)

保存