0

In my app, I have a similar view like Instagram reels where video plays and at bottom there is profile picture, description of video, like button and comments button.

When I click comments button, I would like to show comments table view controller covering upto half screen, with comments and inputbar accessoryview at bottom like below: half screen view controller

When I click inside inputbar accessoryview, the comments view controller show cover fullscreen and should show keyboard like below: full screen view controller

Please advise me on how to achieve this behaviour.

1 Answers1

0

You could create a new ViewController in storyboard or code, then set the set self.view.backgroundColor = .clear (alternatively, you could change the Opacity of the backgroundColor of the view in storyboard by using a custom color).

Next, place a UIView on the storyboard. Create an @IBOutlet for the height constraint of the view. You can get the height of the view (the ViewController's UIView, not the one you just placed) by using


let viewHeight = self.view.frame.size.height
self.commentsView.setHeight(viewHeight/2)

Make sure to include this extension in your project for setHeight:

extension UIView {
   func setHeight(_ h:CGFloat, animateTime:TimeInterval?=nil) {

       if let c = self.constraints.first(where: { $0.firstAttribute == .height && 
         $0.relation == .equal }) {
           c.constant = CGFloat(h)

           if let animateTime = animateTime {
               UIView.animate(withDuration: animateTime, animations:{
                   self.superview?.layoutIfNeeded()
               })
           }
           else {
               self.superview?.layoutIfNeeded()
           }
       }
   }
}
The Swift Coder
  • 390
  • 3
  • 13
  • Thanks for your response. I followed this https://stackoverflow.com/a/45525284/12825905 and was able to achieve the half modal presentation, then in textfield did begin editing I changed the constraints of comments view. working fine :) – Shiva Reddy Feb 23 '21 at 14:35