var*_*uru 7 iphone ios uiswipegesturerecognizer swift
嗨我检查了很多关于在SO中滑动的问题,但有疑问.
在我的应用程序中,我有两个页面1.用户视图控制器2.问题视图控制器
现在我要实现的是在从底部向上滑动用户屏幕时显示问题视图控制器.
我是Ios的新手,所以帮助我实现这个目标.
编辑:
问题是在向上滑动时它应该开始显示另一个视图控制器.如果我用我的手指仍然触摸屏幕滑到屏幕中间,那么它应该显示2个视图控制器.我用这样的推/弹来实现这个
首先,您必须UIPanGestureRecognizer向“问题栏”添加一个,以便您可以平移它以显示问题视图。
要处理多个视图控制器,您可以使用容器视图控制器:
var pendingViewController: UIViewController? {
didSet {
if let pending = pendingViewController {
addChildViewController(pending)
pending.didMoveToParentViewController(self)
pending.view.frame.origin.y = UIScreen.mainScreen().bounds.height
view.addSubview(pending.view)
}
}
}
var currentViewController: UIViewController? { didSet { pendingViewController = nil } }
func showQuestions(recognizer: UIPanGestureRecognizer) {
if recognizer.state == .Began {
let controller = QuestionViewController() // create instance of your question view controller
pendingViewController = controller
}
if recognizer.state == .Changed {
let translation = recognizer.translationInView(view)
// Insert code here to move whatever you want to move together with the question view controller view
pendingViewController.view.center.y += translation.y
recognizer.setTranslation(CGPointZero, inView: view)
}
if recognizer.state == .Ended {
// Animate the view to it's location
}
}
Run Code Online (Sandbox Code Playgroud)
像这样的东西。这些都是手动输入的,所以可能会有一些错误。
| 归档时间: |
|
| 查看次数: |
4868 次 |
| 最近记录: |