简体   繁体   中英

Presented Modal view controller not displayed like a Form

I am new to iOS programming. I am learning How to use Modal in iOS. I have a button. Inside button tap handler. I want to show a UIViewController like Modal form.

Here is my code:

@IBAction func userEditClick(sender: AnyObject) {

    let userCtrl = UserEditViewController(nibName: "UserEditViewController", bundle: nil)
    userCtrl.callback = self

    userCtrl.modalPresentationStyle = UIModalPresentationStyle.FormSheet
    //userCtrl.preferredContentSize = CGSizeMake(400, 800);

    self.presentViewController(userCtrl, animated: true, completion: nil)

}

UserEditViewController is showed BUT the screen look like Normal UIViewController -> This is not what I expected ---> Form Modal

Thanks!

You just call presentViewController. That will do the job. The default animation of the presentViewController is modal. Also when you see the documentation it says that the setting will adapt to the environment. So I think when you are on the iPhone the FormSheet have to cover the whole screen. I think you may stick to the apple's default behavior.

In a horizontally regular environment, a presentation style that displays the content centered in the screen. The width and height of the content area are smaller than the screen size and a dimming view is placed underneath the content. If the device is in a landscape orientation and the keyboard is visible, the position of the view is adjusted upward so that the view remains visible. All uncovered areas are dimmed to prevent the user from interacting with them.

In a horizontally compact environment, this option behaves the same as UIModalPresentationFullScreen.

Available in iOS 3.2 and later.

Ok so if you want to show like form sheet on the iPhone or iPad you need to calculate the size and show them with the animation you make and load it on your view controller.

Or you can check this repository https://github.com/m1entus/MZFormSheetController They did the hard parts :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM