ios - 在另一个 View 前将 View 显示为向上滑动手势

标签 ios swift xcode storyboard

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

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

我正在使用自动布局和 Storyboard。我如何实现这一目标?

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

enter image description here

enter image description here

最佳答案

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

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

Drag Down UIView in iOS 5

或者这个

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

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

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

界面设置

enter image description here

约束设置

enter image description here

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

  • 做一个底 View 高度约束的导出
  • 制作一个按钮的导出,将其标题更改为向上/向下
  • 制作并点击按钮事件

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

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()
        })
    }
}

}

这项工作的输出将是

enter image description here

关于ios - 在另一个 View 前将 View 显示为向上滑动手势,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32514836/

相关文章:

ios - 单击时在 uicollectionviewcell 中切换图像

ios - 检查 ios 设备是否被阻止

ios - dyld 问题库未加载

ios - 如何压缩多个数据而不是多个图像?

Swift 4 静态获取模型属性名称的值

c++ - Xcode LLVM 5.0 错误 -Wunused-command-line-argument-hard-error-in-future

ios - 通过 UIAlertview 处理推送通知

swift - _ : mean in Swift? 是什么

objective-c - App 在设备上不流畅?

iphone - 未找到核心数据实体名称