I tried the following: when loading a view, I create constraints depending on the state:
- (void)setCityConstraints { NSLog(@"set city constraints"); tView.translatesAutoresizingMaskIntoConstraints = NO; NSLayoutConstraint *myConstraint =[NSLayoutConstraint constraintWithItem:self.tView attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:navBar attribute:NSLayoutAttributeBottom multiplier:1.0 constant:0.0]; [self.view addConstraint:myConstraint]; } - (void)setInterCityConstraints { NSLog(@"set intercity constraints"); tView.translatesAutoresizingMaskIntoConstraints = NO; NSLayoutConstraint *myConstraint =[NSLayoutConstraint constraintWithItem:self.tView attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:navBar attribute:NSLayoutAttributeBottom multiplier:1.0 constant:50.0]; [self.view addConstraint:myConstraint]; }
At the first load, everything works fine, but if I start changing the state of the view by changing the segmentedControl, then the second form of the tableView fits on the UIView (where the buttons are From and Where to).
- (IBAction)orderTypeChanged:(id)sender { if (orderTypeControl.selectedSegmentIndex == 0) { [self showCity]; [self setCityConstraints]; } else { [self showIntercity]; [self setInterCityConstraints]; } }