iOS8以后第三方键盘获取高度不对的问题

iOS8以后苹果可以安装第三方键盘,

通过断点我们会发现使用第三方键盘之后,

键盘将要弹出的方法:- (void)keyBoardWillShow:(NSNotification *)notification会执行三次,

三次的高度分别是:0:216:282。我们发现我们需要的是第三次的高度。

我们需要注册键盘隐藏和显示的通知:

[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(keyBoardDidHide:) name:UIKeyboardWillHideNotification object:nil];

[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];

 1 #pragma mark–键盘显示事件
 2
 3 - (void)keyboardWillShow:(NSNotification *)notification {
 4     CGFloat curkeyBoardHeight = [[[notification userInfo] objectForKey:@"UIKeyboardBoundsUserInfoKey"] CGRectValue].size.height;
 5     CGRect begin = [[[notification userInfo] objectForKey:@"UIKeyboardFrameBeginUserInfoKey"] CGRectValue];
 6     CGRect end = [[[notification userInfo] objectForKey:@"UIKeyboardFrameEndUserInfoKey"] CGRectValue];
 7
 8     // 第三方键盘回调三次问题,监听仅执行最后一次
 9     if(begin.size.height>0 && (begin.origin.y-end.origin.y>0)){
10
11         CGFloat keyBoardHeight = curkeyBoardHeight;
12
13         NSLog(@"第三次:%f",keyBoardHeight);
14         [UIView  animateWithDuration:0.05 animations:^{
15             self.bgView.hidden = NO;
16             self.commentToolView.y = kScreenHeight - keyBoardHeight - 44;
17
18         }];
19     }
20 }
21
22 #pragma mark–键盘隐藏事件
23
24 -(void)keyBoardDidHide:(NSNotification *)notification{
25     NSLog(@"键盘隐藏");
26     self.bgView.hidden = YES;
27     self.commentToolView.y = kScreenHeight;
28 }
时间: 2024-08-10 23:30:31

iOS8以后第三方键盘获取高度不对的问题的相关文章

获取第三方键盘高度(包括自带键盘高度)

#pragma 键盘事件 - (void) keyboardWillShown:(NSNotification *) notif { NSDictionary *info = [notif userInfo]; NSValue *value = [info objectForKey:UIKeyboardFrameEndUserInfoKey]; CGSize keyboardSize = [value CGRectValue].size; _keyBoradH = keyboardSize.he

iOS之 利用通知(NSNotificationCenter)获取键盘的高度,以及显示和隐藏键盘时修改界面的注意事项

我们在开发中会遇到这样的情况:调用键盘时需要界面有一个调整,避免键盘遮掩输入框. 但实现时你会发现,在不同的手机上键盘的高度是不同的.这里列举一下: //获取键盘的高度 /* iphone 6: 中文 2014-12-31 11:16:23.643 Demo[686:41289] 键盘高度是 258 2014-12-31 11:16:23.644 Demo[686:41289] 键盘宽度是 375 英文 2014-12-31 11:55:21.417 Demo[1102:58972] 键盘高度是

Android修炼之道—获取软键盘的高度

自动弹出软键盘 editText = (EditText) findViewById(R.id.edit_text); editText.setFocusable(true); editText.setFocusableInTouchMode(true); editText.requestFocus(); InputMethodManager imm = imm.showSoftInput( edtsearch_title, InputMethodManager.RESULT_SHOWN); i

iOS获取键盘的高度(简洁有效)

iOS获取键盘的高度 (2013-03-06 17:45:31) 标签: keyboard textfield textview ios 键盘高度 分类: iOS笔记 - (void)viewDidLoad { [super viewDidLoad]; //增加监听,当键盘出现或改变时收出消息 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKe

UITableView自定义Cell中,纯代码编程动态获取高度

在UITableView获取高度的代理方法中,经常需要根据实际的模型重新计算每个Cell的高度.直接的做法是在该代理方法中,直接根据模型来返回行高:另 [1]-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath 一种比较优雅的方式是将高度的获取方法放在一个单独的frame中[2],frame中包含了该Cell显示需要的数据模型. 但是在IOS8之后,苹果提供了一个

iOS 根据键盘的高度动态改变UIView的高度

在我们使用键盘时常常出现键盘挡着视图这种情况,下面我给大家介绍一种方法可以根据键盘的高度来动态改变视图的度使其可以始终在键盘的上边 在这里视图我用TextView UIKeyboardWillShowNotification//键盘弹出 UIKeyboardWillHideNotification//键盘缩回 //用通知监听键盘的弹出 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboar

创建第三方键盘 customKeyboard

如果需要开发第三方键盘 首先得了解一下苹果官方文档  https://developer.apple.com/library/ios/documentation/General/Conceptual/ExtensibilityPG/Keyboard.html 然后建议看一下 APPExtension http://www.cocoachina.com/ios/20140918/9677.html 键盘应用属于你的hostAPP 所以如果你要了解appGroups来做到两个应用间信息传输 使用方法

在app中屏蔽第三方键盘

iOS8开放了安装第三方键盘的权限,但是在项目开发中,有些情况是需要禁用第三方键盘的.比如说,数字键盘上需要自定义按钮,但是在第三方键盘弹出时,按钮就覆盖在这上面了,在这中情况下,最好的办法是禁用第三方键盘.在UIApplicationDelegate中有一个方法可以做到禁用第三方键盘. //屏蔽第三方键盘 -(BOOL)application:(UIApplication *)application shouldAllowExtensionPointIdentifier:(NSString *

(转载)iOS UILabel自定义行间距时获取高度

本文介绍一下自定义行间距的UILabel的高度如何获取,需要借助一下开源的UILabel控件:TTTAttributedLabel 附下载地址 https://github.com/TTTAttributedLabel/TTTAttributedLabel 下载后,添加到工程里面,导入头文件 #import "TTTAttributedLabel.h" 直接上代码 NSString *str = @"UILabel自定义行间距时获取高度,UILabel自定义行间距时获取高度,