How to present a modal view controller with custom size in center?

后端 未结 2 532
南笙
南笙 2020-12-19 03:41

I want to present a custom-sized modal view controller with animation from the bottom. I can achieve this animation with ModalPresentationStyle to FormSh

2条回答
  •  粉色の甜心
    2020-12-19 03:59

    An easier way is the following

    Present the modal view controller as a form sheet and in the modal view controller add:

    public override void ViewWillLayoutSubviews ()
    {
        base.ViewWillLayoutSubviews ();
        this.View.Superview.Bounds = new RectangleF (0, 0, 900, 700);
    }
    

    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.

提交回复
热议问题