Search code examples
iosswiftuiviewxib

Show view from bottom with options


When I navigate to a certain viewcontroller, I want a view from bottom with options like so...

How can I have such a view...? enter image description here

EDIT 1

I have tried to achieve as suggested in the link using a tableview instead of collection view. And this is what I have...

enter image description here

And dragging down the view gives me this view...

enter image description here

But I come to the view, I don't want the slide up view to cover the entire length of the view, but it should only be of the same size as given in the 1st screenshot. How can I achieve that..?


Solution

  • Assuming you are using same github project that I posted in comment.

    First remove the garbage : File -> TDStickyView

    1. Outlets

      @IBOutlet weak var viewLeft: UIView!
      @IBOutlet weak var viewRight: UIView!
      private var angel : CGFloat = 0
      
    2. From func viewSetup

      :
      :
      // DELETE THESE 2 LINES AND THESE FUNC TOO.
      self.setCursors()  
      self.rotateView(addAngel: 0)
      
    3. From handleGesture

      if aNewOrigin.y <= 60 {
          self.rotateView(addAngel: .pi/8)
      }
      else if aNewOrigin.y >= 60 && aNewOrigin.y < self.frame.height - 100 {
          self.rotateView(addAngel: 0)
      }
      else {
          self.rotateView(addAngel: -.pi/8)
      }
      

    Now add constraints for cursorView,

    1. For left cursor

    enter image description here

    1. For right cursor

    enter image description here

    Now project is stable and let's talk about your requirements.

    1. Change size of tableView on init.

    In viewSetup change

    //topMostY = UIApplication.shared.statusBarFrame.height
    topMostY = parentVC.view.center.y
    // It is the top most Y position of tableview and it can't go above it. Change it according to your requirement.
    
    1. Hide the TableView completely.

    In handleGesture change

    else if sender.state == .ended {
        self.panGestureColView.isEnabled = false
        if velocity.y > 0 {
            // go down
            // UIView.animate(withDuration: 0.3) {
            //     self.frame = CGRect(origin: CGPoint(x: 0, y: self.parentFrame.size.height - self.bottomMostY), size: self.frame.size)
            // }
    
            // Change above commented UIView.animate with below UIView.animate
    
            UIView.animate(withDuration: 0.3, animations: {
                self.frame = CGRect(origin: CGPoint(x: 0, y: self.parentFrame.size.height), size: self.frame.size)
            }) { (isFin) in
                self.removeFromSuperview()
            }
    
        }
        else if velocity.y < 0 {
            // go up
            UIView.animate(withDuration: 0.3) {
                self.frame = CGRect(origin: CGPoint(x: 0, y: self.topMostY), size: self.frame.size)
            }
        }
    }
    

    That's all.