Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to present partial height modal view controller from bottom to top

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..

like image 205
Enamul Haque Avatar asked Sep 06 '18 06:09

Enamul Haque


People also ask

How do I present a view controller from another view controller?

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.


1 Answers

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!

like image 116
Ashley Mills Avatar answered Sep 22 '22 17:09

Ashley Mills