I have a couple of modal view controllers of certain size. I'm trying to avoid the use of custom views (creating full screen black translucent overlay over current view, add the modal view over that view, do the animations, etc) to present it because there is no modalPresentationStyle that fits the size of my controllers.
Now I'm using UIModalPresentationPageSheet but my view is smaller in height and I have an ugly blank space
Desired presentation
_______________
| _______ |
| | | |
| | MyVC | |
| | | |
| ------- |
---------------
Actual presentation
_______________
| | | |
| | MyVC | |
| | | |
| |-------| |
| | blank | |
---------------
If I use the UIModalPresentationFormSheet the container is smaller in width.
I'm trying to figure out how to do it but I don't know if it's possible. What is the solution to the problem of presenting a modal VC smaller than any of the presentationStyles? The only solution is to arrange a "custom modal view controller engine"? Popovers doesn't fit my design requirements :(
This is my solution for a NOT autolayout view (never tried with autolayout) and compliant with iOS 7 and iOS 8.
At first be sure to call the modal view in this way:
With iOS 8 set the preferredContentSize in the viewDidLoad method of the modal view.
This works ALSO when the modal view needs to display the keyboard on iPad.
With previous versions of iOS 8 you should set the bounds after presentViewController call:
This solution worked for me as I had the same issue.
My modal view structure is the following (I use UIModalPresentationCurrentContext at both presenting and presented controllers to achieve transparency in the presented VC)
In ModalViewController I overwrote the following method to fix the positioning issue:
I actually create and size the content view first but in different method.
Hope this helps someone.
One solution is to use UIModalPresentationPageSheet to present a page sheet and then immediately resize the modal view. This is fully explained in this answer to another question.
You can use MZFormSheetController like this:
Even I was struggling with the same issue for quite a while. After giving few tries from many of the answers given here I came up with a solution that worked for me pretty well.
Here is the code while presenting the view controller.
In the xib (if you are using one) in the 'Simulated Metrics' section select 'Freeform' size.
Apart from this you need to write the below code in your presented view controller (i.e.., SomeViewController in this example)
}
This code also works for iOS 7 as well
As some other users here, I also had the problem that the origin of the modal view controller was not correct. After some experiments, I found a solution that worked for me: