利用通知监测键盘高度

 
//键盘的frame发生改变时发出的通知(位置和尺寸)

UIKeyboardWillChangeFrameNotification
 UIKeyboardDidChangeFrameNotification

 //键盘显示时发出的通知

 UIKeyboardWillShowNotification
 UIKeyboardDidShowNotification

 //键盘隐藏时发出的通知

 UIKeyboardWillHideNotification
 UIKeyboardDidHideNotification


//添加观察者 监听键盘变化

- (void)viewDidLoad {

    [super viewDidLoad];

    [[NSNotificationCenterdefaultCenter]addObserver:selfselector:@selector(action:)name:UIKeyboardDidChangeFrameNotificationobject:nil];

}

//监听执行方法

- (void)action:(NSNotification *)notification{

   

    NSLog(@"%@",notification.userInfo);

NSLog(@"%@",notification.userInfo[@"UIKeyboardFrameEndUserInfoKey"]);

    //键盘的frame

    CGRect rect = [notification.userInfo[@"UIKeyboardFrameEndUserInfoKey"]CGRectValue];  

}

//输出键盘动画时间

NSLog(@"%f",[notification.userInfo[@"UIKeyboardAnimationDurationUserInfoKey"]floatValue]);


//userInfo打印出来的信息

 {

    UIKeyboardAnimationCurveUserInfoKey = 7;

    UIKeyboardAnimationDurationUserInfoKey = "0.25";

    UIKeyboardBoundsUserInfoKey = "NSRect: {{0, 0}, {414, 271}}";

    UIKeyboardCenterBeginUserInfoKey = "NSPoint: {207, 871.5}";

    UIKeyboardCenterEndUserInfoKey = "NSPoint: {207, 600.5}";

    UIKeyboardFrameBeginUserInfoKey = "NSRect: {{0, 736}, {414, 271}}";

    UIKeyboardFrameEndUserInfoKey = "NSRect: {{0, 465}, {414, 271}}";

    UIKeyboardIsLocalUserInfoKey = 1;

}

CGRect rect = [NSRect: {{0, 465}, {414, 271}} CGRectValue];转化对象





评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值