Do you know a simple (or not simple) way to hide a view (or anything like a view) and let the othe开发者_StackOverflowr views of the screen use the place left blank ? And make the opposite when showing back that view. Something like Android Visibility = GONE for layers.
Thank you
Many UIKit classes have a property hidden
that does what you want. It is defined in UIView so you will find it in most visual elements you use.
There is no such thing as Visibility.GONE, as far as my research has shown, not even AutoLayout can help you. You have to manually replace the views affected by the optionally shown component (in my case, all the views below the optionalView on bottomView):
- (IBAction)toggleOptionalView:(id)sender {
if (!_expanded) {
self.optionalView.frame = CGRectMake(self.optionalView.frame.origin.x, self.optionalView.frame.origin.y, self.optionalView.frame.size.width, _optionalHeight);
self.bottomView.frame = CGRectMake(self.bottomView.frame.origin.x, self.bottomView.frame.origin.y+_optionalHeight, self.bottomView.frame.size.width, self.bottomView.frame.size.height);
_expanded = YES;
} else {
self.optionalView.frame = CGRectMake(self.optionalView.frame.origin.x, self.optionalView.frame.origin.y, self.optionalView.frame.size.width, 0);
self.bottomView.frame = CGRectMake(self.bottomView.frame.origin.x, self.bottomView.frame.origin.y-_optionalHeight, self.bottomView.frame.size.width, self.bottomView.frame.size.height);
_expanded = NO;
}
}
It is advisable not to hard-code the height of the optional component, otherwise your code breaks every time you edit the XIB/Storyboard. I have a field float _optionalHeight which I set in viewDidLoad, so it is always up to date.
精彩评论