7

I'm migrating older code that used NIBs to use manual view creation (loadView) and Auto Layout. The root view controller is a container VC (with 2 children) that uses auto layout and modally presents a view controller that has its layout specified in a NIB and does not yet use auto layout. All is fine after presentViewController:animated:completion:, but when the modal view is closed with dismissViewControllerAnimated:completion: via delegate call, the presenting view is left in a strange, unusable state where the content is weirdly shifted and does not react to touch.

I have tried to create minimal test case to reproduce the problem, but I've failed to reproduce the issue.

What could be causing this?

Palimondo
  • 7,281
  • 4
  • 39
  • 58

4 Answers4

9

I was setting translatesAutoresizingMaskIntoConstraints = NO; on my root UIView. It appears the "outermost" UIView — the superview at the root of your view hierarchy must use the default translatesAutoresizingMaskIntoConstraints = YES. Once I've removed this, everything worked as expected.

Palimondo
  • 7,281
  • 4
  • 39
  • 58
  • Did you find that this applies to the root view of a child view controller even after it's added to a parent view controller's view hierarchy? – bilobatum Oct 24 '13 at 03:28
  • Hi. i posted a related question with a sample project with the issue here: http://stackoverflow.com/questions/40428075/segue-from-a-slpagingviewswift-vc-and-dismiss-the-destination-vc-to-return i can't find how to implemented the solutions i found in my context (SLPagingView). i would appreciate it a lot if someone can take a look and help, Thanks! – Eyal Ben Yehuda Nov 08 '16 at 16:22
3

I had problems with this when upgrading to IOS 11. The UICollectionView layout was not showing the cells anymore. Fixed by adding the line:

controller.modalPresentationStyle = UIModalPresentationOverFullScreen;
[self presentViewController:controller animated:YES completion:nil];

Not sure why this fixes it but not giving it a presentation style really messes with the presenting controllers underlying layout.

Md1079
  • 1,360
  • 1
  • 10
  • 28
0

I have also the same problem and when i tried this navigation controller it was working fine but not with present viewcontroller. Use this below view controller method along with translatesAutoresizingMaskIntoConstraints to solve this problem.

-(void) viewWillLayoutSubviews
{
    [super viewWillLayoutSubviews];

    self.view.translatesAutoresizingMaskIntoConstraints = NO;
}

Please let me now it you have any concern about it. Thanks

chandan
  • 2,453
  • 23
  • 31
0

A different solution - I found if presenting from a view controller within a container view (as opposed to a subview), if you switch the segue from Modal to Show, your constraints will stay the same on your initial view but still animate as if you presented modally and still be able to call dismissViewController correctly.

Ian Han
  • 507
  • 5
  • 7