//键盘的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];转化对象
本文介绍iOS中如何使用系统提供的键盘通知来监听键盘显示、隐藏及尺寸变化,并展示了如何通过这些通知调整应用界面布局。
641

被折叠的 条评论
为什么被折叠?



