键盘

本文介绍了解决iOS应用中键盘弹出导致页面显示被遮挡的解决方案,通过在viewDidLoad方法中注册键盘弹出和隐藏的观察者,实现了在键盘出现时调整页面布局以保持用户体验,键盘消失后恢复原始布局。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

在看asihttprequest代码时候,无意发现了关于键盘弹出时遮盖页面显示的解决方案,

解决方法如下:

在viewload方法里面注册监听键盘弹出和hide 

[[self viewsetAutoresizingMask:UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth];

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

[[NSNotificationCenter defaultCenteraddObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];


然后在keyboardWillShow修改页面的大小- 键盘的高度

- (void)keyboardWillShow:(NSNotification *)notification

{

#if __IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_3_2

NSValue *keyboardBoundsValue = [[notification userInfo] objectForKey:UIKeyboardFrameEndUserInfoKey];

#else

NSValue *keyboardBoundsValue = [[notification userInfoobjectForKey:UIKeyboardBoundsUserInfoKey];

#endif

CGRect keyboardBounds;

[keyboardBoundsValue getValue:&keyboardBounds];

UIEdgeInsets e = UIEdgeInsetsMake(00, keyboardBounds.size.height-420);

[[self tableViewsetScrollIndicatorInsets:e];

[[self tableViewsetContentInset:e];

}

恢复正常页面

- (void)keyboardWillHide:(NSNotification *)notification

{

UIEdgeInsets e = UIEdgeInsetsMake(0000);

[[self tableViewsetScrollIndicatorInsets:e];

[[self tableViewsetContentInset:e];

}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值