gpt4 book ai didi

ios - 当键盘处于事件状态时,如何阻止我的 UITableView 在重新加载时不恰本地更改弹出窗口中的大小?

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:10:58 24 4
gpt4 key购买 nike

我的设计需要在应用程序的根以外的某个地方使用相当于 UISplitViewController 的东西。由于某些愚蠢的原因(感谢 Apple)这是非法的,我不得不手动重新编码它的某些方面。

表格在横向模式下布局正确,但当我将其移动到弹出窗口时,我遇到了一些奇怪的问题。最初,我的弹出窗口足够长,以至于它必须收缩才能为键盘提供空间,结果是 TableView 太大,最终被剪掉了。所以我缩小了弹出窗口......现在当我重新加载它的数据时 TableView 正在缩小自己(当用户输入搜索键时我必须这样做)。请注意,错误仅在 我重新加载 tableView 之后显示;而不是裁剪,现在它正在收缩,它是顶部和底部的“带拳击”。

当我查询框架数据时,tableView 奇怪地似乎保持了它的高度。那是什么意思我不知道。如果我关闭弹出窗口并表示它,它不会解决问题(我认为弹出窗口最终会变大?),但是当我记忆起键盘时它确实如此(弹出窗口缩小到正确的高度)。 (我不想尝试将其作为解决方法,因为这只会让积极打字的用户感到厌烦)。

编辑:

如果重要的话,我唯一应用的自动布局是 UITableView;它被赋予了固定的宽度和高度。没有 X 或 Y 数据,这可能是一个错误,除非我在尝试引用 super View 时生成错误——可能是因为弹出窗口在我尝试呈现 super View 之前不会创建它?

编辑:请求的代码(抱歉,这是一个又大又丑的 block ):

-(void)setupViewsAfterRotation
{
if (UIInterfaceOrientationIsPortrait([UIApplication sharedApplication].statusBarOrientation)) {
[self.searchTable.view removeFromSuperview];
self.popover=[[UIPopoverController alloc] initWithContentViewController:self.searchTable];
self.navigationItem.leftItemsSupplementBackButton=YES;
self.navigationItem.leftBarButtonItem=[[UIBarButtonItem alloc] initWithTitle:@"Search"
style:UIBarButtonItemStylePlain
target:self
action:@selector(presentPopover)];
[self setupPortraitConstraints];
//NSLog(@"Intrinsic size data: width: %f and height: %f",self.searchTable.view.intrinsicContentSize.width, self.searchTable.view.intrinsicContentSize.height);
//NSLog(@"Runtime size data: width: %f and height: %f",self.searchTable.view.frame.size.width, self.searchTable.view.frame.size.height);

} else {
[self.popover dismissPopoverAnimated:NO];
self.popover=nil;
self.navigationItem.leftBarButtonItem=nil;
[self.view addSubview:self.searchTable.view];
[self setupLandscapeConstraints];
}
}

-(void)setupLandscapeConstraints
{
if (self.tableViewConstraints) {
[self.view removeConstraints:self.tableViewConstraints];
self.tableViewConstraints=nil;
}
NSMutableArray *landscapeConstraints=[[NSLayoutConstraint constraintsWithVisualFormat:@"|[tableView(==256)]"
options:0
metrics:nil
views:@{@"tableView": self.searchTable.view}] mutableCopy];

[landscapeConstraints addObjectsFromArray:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[topLayoutGuide][tableView]|"
options:0
metrics:nil
views:@{@"tableView": self.searchTable.view,
@"topLayoutGuide":[self topLayoutGuide]
}]];
self.tableViewConstraints=landscapeConstraints;
[self.view addConstraints:self.tableViewConstraints];
}

-(void)setupPortraitConstraints
{
if (self.tableViewConstraints) {
[self.view removeConstraints:self.tableViewConstraints];
self.tableViewConstraints=nil;
}
NSMutableArray *portraitConstraints;
if (self.keyboardHeight) {
NSLog(@"Height set to 612");
portraitConstraints=[[NSLayoutConstraint constraintsWithVisualFormat:@"V:[tableView(==612)]"
options:0
metrics:nil
views:@{@"tableView": self.searchTable.view}] mutableCopy];
[self.popover setPopoverContentSize:CGSizeMake(256, 612) animated:YES];
}
else{
NSLog(@"Height set to 768");
portraitConstraints=[[NSLayoutConstraint constraintsWithVisualFormat:@"V:[tableView(==768)]"
options:0
metrics:nil
views:@{@"tableView": self.searchTable.view}] mutableCopy];
[self.popover setPopoverContentSize:CGSizeMake(256, 768) animated:YES];
}

[portraitConstraints addObjectsFromArray:[NSLayoutConstraint constraintsWithVisualFormat:@"[tableView(==256)]"
options:0
metrics:nil
views:@{@"tableView": self.searchTable.view}]];
self.tableViewConstraints=portraitConstraints;
[self.searchTable.view addConstraints:self.tableViewConstraints];
}

最佳答案

设置弹出窗口的内容大小以限制弹出窗口的 View 区域。

您可以通过以下方式做到这一点:

  1. 使用方法 setPopoverContentSize: 设置弹出窗口的内容大小。
  2. 为内容 View Controller 设置 contentSizeForViewInPopover。

来自 Apple's Documentation :

Popovers normally derive their size from the view controller they present. However, you can change the size of the popover by modifying the value in the popoverContentSize property or by calling the setPopoverContentSize:animated: method. The latter approach is particularly effective if you need to animate changes to the popover’s size. The size you specify is just the preferred size for the popover’s view. The actual size may be altered to ensure that the popover fits on the screen and does not collide with the keyboard.

来自 Apple's documentation关于 popoverContentSize 属性:

Changing the value of this property overrides the default value of the current view controller. The overridden value persists until you assign a new content view controller to the receiver. Thus, if you want to keep your overridden value, you must reassign it after changing the content view controller.

关于ios - 当键盘处于事件状态时,如何阻止我的 UITableView 在重新加载时不恰本地更改弹出窗口中的大小?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18842245/

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