I want to present a custom-sized modal view controller with animation from the bottom. I can achieve this animation with ModalPresentationStyle
to FormSheet
, but it forces me to use the default size which is 540x620 and my view doesn't fit.
How do I make perform a similar transition to an arbitrarily sized view (controller) placed in center of the screen?
I didn't find a way to do it from the modal controller itself so I created a class and an extension method:
This is roughly how I use it:
It is convenient that I don't need to specify the size explicitly because it uses root View's bounds from the interface builder. I'm not sure how this reacts to autorotate, it may need some tuning. I'm also using two extension methods here:
And this is it.
An easier way is the following
Present the modal view controller as a form sheet and in the modal view controller add:
It is important to set the desired width and height if you don't want ios to assign the default form sheet size
Update: In ios 8 at least there are some situation when the solution above triggeres an infinte loop. It seems that in some situations (like when having an embedded webview in the modal view and tapping in some html input text) changing the superview bounds triggers layout on the modal view resulting in an infinite loop and freeze of the app. But in ios 8 you can simply set the PrefferedSize property to achieve the same effect.