Search code examples
iosswiftpresentviewcontroller

Swift - iOS 9: How do i present UIViewController with custom size in iOS 9?


i have a view and i want to display a UIViewController with custom size. But i didn't succeed. Here is my code.

var vx = KeyboardViewController()
vx.modalPresentationStyle = UIModalPresentationStyle.FormSheet
vx.preferredContentSize = CGSizeMake(self.view.frame.width, 150)    
self.presentViewController(vx, animated: true, completion: nil)

This UIViewController is displayed in the full screen size


Solution

  • You need to give the presented view controller a custom transitioningDelegate, which will then be able to insert a custom UIPresentationController into the presentation process, whose frameOfPresentedViewInContainerView you will have overridden appropriately.