在另一个视图前将视图显示为向上滑动手势

Show a view as a swipe up gesture in front of another view

您好,我正在开发具有 UI 如下图所示的应用程序..

我无法理解如何创建底部向上滑动视图。 我试过在底部视图上向上滑动手势来打开它。 但我想用手指打开底部视图(意味着缓慢向上拖动视图应该慢慢显示底部视图)

我正在使用自动布局和故事板。我该如何实现?

我搜索了很多,找到了这个 https://github.com/crocodella/PullableView 但我无法使用情节提要和自动布局添加此视图。

我只想说,在解决方案之前,这不会像拖动效果那样需要使用手势...但是如果您非常需要通过单击按钮获得类似效果,它会为您提供类似的效果。我认为它不是你想要的,但如果你愿意,这会给你一个选择

要将底部视图拖到顶部,您应该使用手势,这可能会对您有所帮助

Drag Down UIView in iOS 5

或这个

http://www.jondev.net/articles/Dragging_View_with_Finger_(iPhone)

你使用 constant 属性 约束得到了类似的效果..比如给底部视图高度约束并在点击事件上使用常量 属性 上下滑动。

还是一头雾水!!!这是解决方案

UI设置

约束设置

之后你只需要制作一些插座并点击按钮事件...

  • 设置底视图高度限制的出口
  • 制作按钮的出口以将其标题更改为up/down
  • 制作并点击按钮事件

完成此过程后,您需要对按钮操作进行编码,下面是代码

class ViewController: UIViewController {

   // Button outlet
   @IBOutlet weak var btnUp: UIButton! 

   // Height Constraint outlet
   @IBOutlet weak var constHeightBottomView: NSLayoutConstraint!

   // Boolean property to handle click
   var clicked = true

override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view, typically from a nib.
}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}

@IBAction func btnUpClicked(sender: UIButton) {
    if clicked{
        self.clicked = !clicked
        UIView.animateWithDuration(0.2, animations: {
            self.btnUp.setTitle("Down", forState: .Normal)
            self.constHeightBottomView.constant = 200
            self.view.layoutIfNeeded()
        })

    }
    else{
        self.clicked = true

        UIView.animateWithDuration(0.2, animations: {
            self.btnUp.setTitle("Up", forState: .Normal)
            self.constHeightBottomView.constant = 0
            self.view.layoutIfNeeded()
        })
    }
}

}

这项工作的输出将是