2017-09-15 75 views
0

我想隐藏一个UIView,但目前为止没有任何工作。 UIView位于UITableView的底部,而不是作为一个单元格。这是我到目前为止的尝试:无法完全隐藏UIView

self.viContainerLocation.hidden = YES; 
self.viContainerLocation.alpha=0.0; 

CGRect Conframe = self.viContainerLocation.frame; 
Conframe.size.height = self.view.bounds.size.height; 
self.viContainerLocation.frame = Conframe; 

self.tableView.translatesAutoresizingMaskIntoConstraints=NO; 

__block CGRect frame=self.tableView.frame; 
frame.size.height= self.view.frame.size.height-frame.origin.y; 
frame.size.width=self.view.frame.size.width; 
self.tableView.frame=frame; 

viContainerLocation是我试图隐藏的UIView。上面的代码隐藏了UIView中的所有元素,但留下了UIView维度的空白区域。 对于原因,我不明白,viContainerLocation是隐藏的,当我使用此代码:

[UIView transitionWithView:self.viContainerLocation 
duration:0.0 
options:UIViewAnimationOptionTransitionCrossDissolve 
animations:^{ } 
completion:^(BOOL finish){ 
__block CGRect frame=self.tableView.frame; 
frame.size.height= self.view.frame.size.height-frame.origin.y; 
frame.size.width=self.view.frame.size.width; 
self.tableView.frame=frame; 
}]; 

但是使用这个代码的空白被显示在几分之一秒的,它看起来并不好。

我该如何让它从一开始就离开?

+0

尽量去除代码 “self.tableView.translatesAutoresizingMaskIntoConstraints = NO;” –

+0

尝试在最后设置'self.viContainerLocation.hidden = YES;'而不是乞求 –

回答

2

你误解了一些东西。

当隐藏UIView时,该视图占用的空间仍然可见。 如果你想要你的tableview填充缺失的空间,最快的方法是将你的tableview和你的视图加入UIStackView

UIStackView当您将一个子视图设置为isHidden=true时,视图被删除,其他视图填充左侧空间。

更多的相关信息的位置:https://developer.apple.com/documentation/uikit/uistackview