我有一个UIView
- 叫它HomeView
包含 aUITableView
和 a UISearchBar
。也就是说,它们是子视图。这些被添加到viewDidLoad
for 中HomeView
。一张图片胜过千言万语:
从这些屏幕截图中可以看出,UITableView
一旦显示 ,就会隐藏中的第一项UISearchBar
。以下是相关代码:
- (void) viewDidLoad
self.table_view = [UITableView.alloc.initWithFrame: self.view.bounds style:UITableViewStylePlain];
self.table_view.bounds.origin.y += 44;
self.table_view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
// ^^^ This is the code I believe is one source of my problem
// Triggered when search button in nav bar is pressed
// code to calculate delta here
// Here's how the view is animated. The search bar frame
// is dropped down (works), and ideally, the tableview
// drops down exactly the same amount at the same time.
// If the action is to hide, then the inverse happens
// because +delta+ will have been calculated as a
// negative number above.
[UIView animateWithDuration: 0.7
delay: 0.0
options: UIViewAnimationOptionCurveEaseIn
animations:^ {
self.searchBar.frame = CGRectOffset(@searchBar.frame, 0.0, delta);
}
completion:^(BOOL finished){
self.searchBarVisible = !self.searchBarVisible
self.searchBar.hidden = !self.searchBarVisible
edgeInsets = UIEdgeInsetsMake(0.0f, self.searchBarVisible ? delta : 0.0f, 0.0f, 0.0f)
[tableView setContentInset: edgeInsets]
}
];
实际发生的情况是搜索栏按预期向下滑动以响应按下搜索按钮,然后在按下下一个按钮时向上滑动。但是,表格视图永远不会调整。
据我所知,问题在于,在 中,尚未渲染viewDidLoad
封闭,因此大小尚不清楚。HomeView
我可以获取屏幕尺寸并使用它,但我认为自动调整大小蒙版是更好的做法,对吧?
这是否有明显的缺陷,有没有办法让表格视图在搜索栏的同时向下动画?
谢谢