student
student

Reputation: 179

Unable to hide UIView completely

I am trying to hide a UIView but nothing work so far. The UIView is at the bottom of a UITableView, not inside it as a cell. Here is what I tried so far:

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 is the UIView I am trying to hide. The above code hide all elements inside the UIView, but leaves a white space with the dimensions of the UIView. For a reason I don't understand, viContainerLocation is hidden when I use this code:

 [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; 
 }];

But using this code the white space gets displayed of a fraction of a second and it doesn't look good.

How can I make it go away from the beginning ?

Upvotes: 0

Views: 128

Answers (1)

CZ54
CZ54

Reputation: 5586

You are misunderstanding something.

When hidding an UIView, the space occupied by this view is still visible. If you want your tableview filling the missing space, the quickest way is to ember your tableview and your view into a UIStackView.

In a UIStackView when you set one subview to isHidden=true, the view is removed, and other views fill the left space.

More infos here : https://developer.apple.com/documentation/uikit/uistackview

Upvotes: 2

Related Questions