Ivan Cantarino
Ivan Cantarino

Reputation: 3246

Can't Present View Controller Modally, with specific size

I have a View Controller in which it presents another view controller, modally (bottom-top animation).

I'm trying to present the View Controller, with a specific size, I want it to be presented modally , but in this case to be 80% of it's native size.

let newVC = tabBarController.storyboard?.instantiateViewController(withIdentifier: "newPostVC") as? NewPostVC
newVC.view.frame = CGRect(x: 0, y: 0, width: tabBarController.view.frame.width, height: tabBarController.view.frame.height * 0.8)

tabBarController.present(newVC, animated: true)

But the view controller gets presented in its full size (screen size). I think that I've to twerk the view controller's size, but I might be wrong.

My view controller in the storyboard has it's Transitional Style set to: Cover Vertical and the Presentation is set to: Full Screen.

Could this be the issue?

Can you give me a hint?

Thanks :)

Upvotes: 1

Views: 1354

Answers (1)

Priyatham51
Priyatham51

Reputation: 1884

Try doing something like this.

Create a ContainerVC programmatically add newVC as a subView . In the ContainerVC viewDidLoad()

  1. set constraints on newVC to be 80% of the container size. You can use some framework like Anchorage to easily set this constraints.
  2. set your backgroundColor = .clear
  3. Set the presentation style to .overCurrentContext like this modalPresentationStyle = .overCurrentContext

While presenting it you can something like this

//create view controller
    let VC = ContainerVC()
//present modal
    self.present(VC, animated: true, completion: nil) 

Upvotes: 1

Related Questions