我很熟悉
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虚拟键盘大小没有通知中心所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)