I have used view controller as a modal. I want to specify its height from bottom to top. That means it opens from bottom to its height. I have used bellow code for opening modal:
let popUpVc = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "NewController") as! NewController
self.addChildViewController(popUpVc)
//Transition from bottom
let transition = CATransition()
transition.duration = 0.5
transition.type = kCATransitionPush
transition.subtype = kCATransitionFromTop
view.window!.layer.add(transition, forKey: kCATransition)
popUpVc.view.frame = self.view.frame
self.view.addSubview(popUpVc.view)
popUpVc.modalPresentationStyle = UIModalPresentationStyle.overCurrentContext
popUpVc.didMove(toParentViewController: self)
Please help me..
Using segues in your storyboard is the recommended way to present and dismiss view controllers. A segue is a visual representation of a transition from one view controller to another. A segue starts with an action such as a button tap or table-row selection in the initial view controller.
Reading your comment it seems like you want to cover, say, the bottom half of the parent view with a modal view controller. If you're using storyboards, you can do this pretty easily using a contained view controller…
In the example below, the Show button is presenting the containing view controller modally, with a presentation type of over current context.
The view controller has a clear background, and a containing view set to half it's height. The contained (yellow) view controller has a dismiss button hooked up to an unwind segue in the green view controller.
@IBAction func unwind(_ segue: UIStoryboardSegue) { }
All that with one line of code!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With