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 :(
I obtained the following result (link text) by using:
and by presenting it as a modal view controller. Let me know if you need further help.
The approaches described above need to be tweaked for iOS7:
(This code also works on iOS6.)
even for reducing the forma sheet height and width you can use
The best way to do this is to change the bounds property on the superview of the view being presented inside the formsheet. When you present a view modally, the presented view is embedded inside another view.
You should set the bounds property of the superview to the same rect as the view's bounds. First add a private ivar in your class:
It's best to do this in
viewWillAppear:
. Add the following code to the view controller that is being presented modally:You need to cache
_realBounds
in yourviewDidLoad
method:I had an issue getting the custom sized modal to center until I figured out what
ViewController.view.superview.frame
was set to initially. It is determined based on the UIModalPresentation type.superview.center
isn't even needed(as far as my testing shows).Also, I set the coordinates dynamically using
[UIScreen mainScreen].applicationFrame
, only supporting landscape orientation for now. You have to do a conditional check to support both portrait and landscape by flipping the X/Y and Height/Width values.Here was my first working solution for iOS 6.0:
And then I looked at the previous answer and face palmed. Shortens my solution a tad by replacing the last line with:
EDIT for final solution and remarks.
Resize the modal view "after" it is presented using presentModalViewController method.See this link to resize modal View https://coderwall.com/p/vebqaq