Show view from bottom with options

匆匆过客 提交于 2019-12-02 23:00:00

问题


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

How can I have such a view...?

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

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

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


回答1:


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

  1. For right cursor

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.



来源:https://stackoverflow.com/questions/55137798/show-view-from-bottom-with-options

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!