11

I'd like to create a sort of popup view that is displayed in a main controller through custom transitions.

I create the popup viewcontroller into a storyboard and I set its view as freeform, then I resize the view.

My problem is that when I load the view controller using instantiateViewControllerWithIdentifier the view bounds are always reset to full screen.

Here is the code that I'm using, the popUp size should be 100x100, but from this code I get 320X480.

self.popUp = (PopUpViewController*)[storyBoard instantiateViewControllerWithIdentifier:@"Popup"];

NSLog(@"%@",NSStringFromCGRect(self.popUp.view.bounds));

How can I setup a freeform view controller and load it programmatically with the right size?

5
  • 2
    Just set the frame yourself. self.popUp.view.frame = CGRectMake(w, x, y, z);
    – Fogmeister
    Nov 14, 2013 at 10:09
  • or add a transparent view @desired location and do self.viewforpopup addsubview:popup Nov 14, 2013 at 10:26
  • @Fogmeister I thought about this solution that it is obvious :P but I'd like to understand why that happens and eventually find a way to avoid this "problem".
    – MatterGoal
    Nov 14, 2013 at 10:36
  • 1
    AFAIK when you add a VC to a storyboard it has no inherent size. It gets it's size from its parent. This can either be another VC or a container view. If you use a container view then the size of the view of the new VC will be that of the container. The flag of "freeform" is purely an aide to editing the look of the controller. It is not a run time attribute.
    – Fogmeister
    Nov 14, 2013 at 11:52
  • @Fogmeister I suppose this could be the answer! :)
    – MatterGoal
    Nov 14, 2013 at 15:14

1 Answer 1

21

Solution at Wrong frame value while accessing the view from storyboard in IOS worked for me.

Uncheck the "Resize View From Nib" box in the inspector. That should give you the correct size for a freeform view controller.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.