Show view from bottom with options

旧时模样 提交于 2019-12-02 12:56:38

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.

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