gpt4 book ai didi

iphone - 以编程方式更改 UITableView 的滚动插图以反射(reflect) iPhone 键盘的大小

转载 作者:行者123 更新时间:2023-12-03 20:24:52 25 4
gpt4 key购买 nike

我知道您可以使用 Interface Builder 中的“Inset”属性使 ScrollView 从主窗口插入,这样它就不会低于屏幕上现有的控件(例如选项卡栏),但是您怎么能以编程方式执行此操作以在键盘添加到屏幕时进行调整?目前,我的 ScrollView 在键盘下方有无法到达的单元格,因为该 View 仍在将 ScrollView 的底部注册为手机的底部,而不是键盘的顶部。

最佳答案

#pragma mark Keyboard Handling



- (void) viewDidAppear:(BOOL) ani {
onscreen = YES;

NSNotificationCenter* center = [NSNotificationCenter defaultCenter];
[center addObserver:self selector:@selector(keyboardWillAppear:) name:UIKeyboardWillShowNotification object:nil];
[center addObserver:self selector:@selector(keyboardDidAppear:) name:UIKeyboardDidShowNotification object:nil];
[center addObserver:self selector:@selector(keyboardWillDisappear:) name:UIKeyboardWillHideNotification object:nil];
}

- (void) viewDidDisappear:(BOOL) ani {
onscreen = NO;

NSNotificationCenter* center = [NSNotificationCenter defaultCenter];
[center removeObserver:self name:UIKeyboardWillShowNotification object:nil];
[center removeObserver:self name:UIKeyboardDidShowNotification object:nil];
[center removeObserver:self name:UIKeyboardWillHideNotification object:nil];
}

- (void) keyboardWillAppear:(NSNotification*) n {
NSLog(@"Keyboard is about to appear");
}

- (void) keyboardDidAppear:(NSNotification*) n {

CGRect bounds = [[[n userInfo] objectForKey:UIKeyboardBoundsUserInfoKey] CGRectValue];
bounds = [self.view convertRect:bounds fromView:nil];

CGRect tableFrame = searchResultsTable.frame;
tableFrame.size.height -= bounds.size.height; // subtract the keyboard height
if (self.tabBarController != nil) {
tableFrame.size.height += 48; // add the tab bar height
}

[UIView beginAnimations:nil context:NULL];

[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(shrinkDidEnd:finished:contextInfo:)];
searchResultsTable.frame = tableFrame;
[UIView commitAnimations];

//[self hideEditorView:currentEditorView];
//[currentEditorView removeFromSuperview];
}

- (void) shrinkDidEnd:(NSString*) ident finished:(BOOL) finished contextInfo:(void*) nothing {
NSIndexPath* sel = [searchResultsTable indexPathForSelectedRow];

if (![[searchResultsTable indexPathsForVisibleRows] containsObject:sel])
{
[searchResultsTable scrollToNearestSelectedRowAtScrollPosition:UITableViewScrollPositionMiddle animated:YES];
}
}

- (void) keyboardWillDisappear:(NSNotification*) n {
CGRect bounds = [[[n userInfo] objectForKey:UIKeyboardBoundsUserInfoKey] CGRectValue];
bounds = [self.view convertRect:bounds fromView:nil];

CGRect tableFrame = searchResultsTable.frame;
tableFrame.size.height += bounds.size.height; // add the keyboard height

if (self.tabBarController != nil) {
tableFrame.size.height -= 48; // subtract the tab bar height
}

[UIView beginAnimations:nil context:NULL];

[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(shrinkDidEnd:finished:contextInfo:)];
searchResultsTable.frame = tableFrame;
[UIView commitAnimations];

[searchResultsTable scrollToNearestSelectedRowAtScrollPosition:UITableViewScrollPositionMiddle animated:YES];
}

关于iphone - 以编程方式更改 UITableView 的滚动插图以反射(reflect) iPhone 键盘的大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1312975/

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