iOS虚拟键盘大小没有通知中心

iOS虚拟键盘大小没有通知中心,第1张

概述当需要点击虚拟键盘的textFiewl时,我需要向上滚动我的scrollView.我调用[self.scrollView setContentOffset:scrollPoint animated:YES] ;.要获得屏幕的可见区域,我显然需要KB大小. 我很熟悉 NSDictionary *info = [notification userInfo];CGSize kbSize = [sel 当需要点击虚拟键盘的textFIEwl时,我需要向上滚动我的scrollVIEw.我调用[self.scrollVIEw setContentOffset:scrollPoint animated:YES] ;.要获得屏幕的可见区域,我显然需要KB大小.

我很熟悉

NSDictionary *info = [notification userInfo];CGSize kbSize = [self.vIEw convertRect:                 [info[UIKeyboardFrameBeginUserInfoKey] CGRectValue]                              fromVIEw:nil].size;

但是,它对我不起作用,因为当用户点击可能半隐藏的文本字段时,我没有收到键盘通知.

所以我调用textFIEldDIDBeginEditing:中的方法,在键盘发送消息之前调用它,所以我不知道第一次点击时的KB大小.

所以问题是:是否可以获得KB大小,而无需调用相应的通知?
Programmaticaly,而不是硬编码.

解决方法 你做错了.

您还需要听取键盘显示/隐藏通知,然后调整屏幕.

这是一个示例框架代码:

- (voID)vIEwWillAppear:(BOol)animated{    [super vIEwWillAppear:animated];    NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];    [nc addobserver:self selector:@selector(keyboardChangedStatus:) name:UIKeyboarDWillShowNotification object:nil];    [nc addobserver:self selector:@selector(keyboardChangedStatus:) name:UIKeyboarDWillHIDeNotification object:nil];}- (voID)vIEwWilldisappear:(BOol)animated {    [super vIEwWilldisappear:animated];    NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];    [nc removeObserver:self name:UIKeyboarDWillShowNotification object:nil];    [nc removeObserver:self name:UIKeyboarDWillHIDeNotification object:nil];}#pragma mark - Get Keyboard size- (voID)keyboardChangedStatus:(NSNotification*)notification {    //get the size!    CGRect keyboardRect;    [[[notification userInfo] objectForKey:UIKeyboardFrameEndUserInfoKey] getValue:&keyboardRect];    keyboardHeight = keyboardRect.size.height;    //move your vIEw to the top,to display the textfIEld..    [self moveVIEw:notification keyboardHeight:keyboardHeight];}#pragma mark VIEw Moving- (voID)moveVIEw:(NSNotification *) notification keyboardHeight:(int)height{    [UIVIEw beginAnimations:nil context:NulL];    [UIVIEw setAnimationDuration:0.3];    [UIVIEw setAnimationBeginsFromCurrentState:YES];    CGRect rect = self.vIEw.frame;    if ([[notification name] isEqual:UIKeyboarDWillHIDeNotification]) {        // revert back to the normal state.        rect.origin.y = 0;        hasScrolledTotop = YES;    }     else {        // 1. move the vIEw's origin up so that the text fIEld that will be hIDden come above the keyboard (you need to adjust the value here)        rect.origin.y = -height;    }    self.vIEw.frame = rect;    [UIVIEw commitAnimations];}
总结

以上是内存溢出为你收集整理的iOS虚拟键盘大小没有通知中心全部内容,希望文章能够帮你解决iOS虚拟键盘大小没有通知中心所遇到的程序开发问题。

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

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

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

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

发表评论

登录后才能评论

评论列表(0条)

保存