gpt4 book ai didi

iphone - UIView 内容剪辑不起作用/UIView 调整大小不起作用

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

我遇到了一个问题,即 subview 的裁剪无法始终如一地工作(或者 UIView 调整大小可能无法正常工作)。场景如下:

  • 我有一个 UIView(行上方的部分)。实际尺寸更大以容纳搜索栏。我基本上是在 viewDidLoad 上调整它的大小。
  • 单击文本字段时,UIView 展开并显示搜索栏
  • 搜索后,我折叠了 UIView,但发现在某些情况下 UIView 没有折叠(见第一张图片)。如果我不隐藏搜索栏,它也会保留。

出现这个问题有什么原因吗?我仍在尝试调试并查看是否有任何可能导致此问题的原因(因为某些东西可能会重置为原始大小)。确实看起来所有内容都已正确调整大小,因为即使结果表也已正确移动。在预期的调整大小之后,一定有其他东西触发了它。任何指针表示赞赏。我只做了 5 天的 iOS 开发,所以我仍然不知道很多事情。

- (void)showAddressField
{
CGRect headerFrame = self.searchHeaderView.frame;
headerFrame.size.height = headerHeight + adjustmentSize;
self.searchHeaderView.frame = headerFrame;

CGRect tableFrame = resultTableView.frame;
tableFrame.size.height = tableHeight - adjustmentSize;
tableFrame.origin.y = headerFrame.size.height + statusBarHeight;
resultTableView.frame = tableFrame;

[self renderHeaderBorder:headerFrame.size.height - 1];
}

- (void)hideAddressField
{
CGRect headerFrame = self.searchHeaderView.frame;
headerFrame.size.height = headerHeight;
self.searchHeaderView.frame = headerFrame;

CGRect tableFrame = resultTableView.frame;
tableFrame.size.height = tableHeight;
tableFrame.origin.y = headerHeight + statusBarHeight;
resultTableView.frame = tableFrame;

[self renderHeaderBorder:headerHeight - 1];

已编辑

SearchHeaderView 只是一个 UIView,它是主视图的 subview 。它不是表格标题。我发现,如果我在表格标题中放置一个搜索栏,它的行为将非常不可预测,因此我有一个包含搜索部分的 UIView,并在其正下方有一个 UITableView。

抱歉,因为我只有一个多星期的时间来从头开始制作一个相当庞大的应用程序,所以我没有时间等待。我已经稍微改变了我的方法,但即使在赏金到期后我仍然会奖励积分。我试图了解与布局有关的所有内容,因为这几乎是我在 iOS 应用程序开发中唯一不太明白的事情。

UIView Clip Subviews Issue UIView expanded

最佳答案

如果搜索栏位于 TableView 标题中,请尝试将标题 View 重新分配给 TableView :

[tableView setTableHeaderView:self.searchHeaderView];

如果它是节标题,请务必更新代表的值

– tableView:heightForHeaderInSection:
– tableView:viewForHeaderInSection:

否则,请发布更多关于如何初始化 searchHeaderView 并将其添加到表中的代码。

希望这对您有所帮助!

关于iphone - UIView 内容剪辑不起作用/UIView 调整大小不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18477334/

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