您好,我正在开发具有如下图所示 UI 的应用程序。
我无法理解如何创建底部向上滑动 View 。 我试过在底部 View 上向上滑动手势来打开它。 但我想用手指打开底部 View (意味着缓慢向上拖动 View 应该慢慢显示底部 View )
我正在使用自动布局和 Storyboard。我如何实现这一目标?
我搜索了很多,找到了这个 https://github.com/crocodella/PullableView但我无法使用 Storyboard和自动布局添加此 View 。
最佳答案
我只想说,在解决方案之前,这不会像拖动效果那样需要使用手势...但是如果您非常需要通过单击按钮获得类似效果,它会为您提供类似的效果。我认为这不是什么你想要,但如果你愿意,这会给你一个选择
要将底部 View 拖到顶部,您应该使用手势,这可能对您有帮助
或者这个
http://www.jondev.net/articles/Dragging_View_with_Finger_(iPhone)
使用约束的 constant
属性得到了类似的效果..比如给底部 View 高度约束,并在点击事件上使用常量属性上下滑动。
还是一头雾水!!!这是解决方案
界面设置
约束设置
之后你只需要制作一些 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()
})
}
}
}
这项工作的输出将是
关于ios - 在另一个 View 前将 View 显示为向上滑动手势,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32514836/