gpt4 book ai didi

objective-c - 如何在键盘打开的同时滚动表格 View ?

转载 作者:行者123 更新时间:2023-11-30 13:06:51 24 4
gpt4 key购买 nike

我想要控制打开的键盘并能够同时滚动表格 View 。我现在必须关闭键盘才能滚动表格 View 。

最佳答案

您在 viewDidLoad 中注册通知并在 viewWillDisappear 中取消注册通知

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

简单地通过键盘的高度调整tableview的contentInset,然后将单元格滚动到底部:

- (void)keyboardWillShow:(NSNotification *)aNotification
{
NSDictionary* info = [aNotification userInfo];
CGSize kbSize = [[info objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size;

UIEdgeInsets contentInsets = UIEdgeInsetsMake(0.0, 0.0, kbSize.height, 0.0);
self.myTableView.contentInset = contentInsets;
self.myTableView.scrollIndicatorInsets = contentInsets;


}

- (void)keyboardWillHide:(NSNotification *)aNotification
{
[UIView animateWithDuration:.3 animations:^(void)
{
self.myTableView.contentInset = UIEdgeInsetsZero;
self.myTableView.scrollIndicatorInsets = UIEdgeInsetsZero;
}];
}

关于objective-c - 如何在键盘打开的同时滚动表格 View ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39261750/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com