Question
What IOS approach is recommended (or is there an IOS control for this I'm not aware of) to allowing the user to drag the spit between two UIView up and down?
Say there is View A at the top of the screen and View B at the bottom (within a container view), then the ability to allow the user to drag the horizon split point up or down. (so I'm not talking about the iPad/IOS split view controller here just to be clear, or the new application split views in IOS9)
Aspects of the Question of Interest
Is this the way to try to implement this now with autolayout and all?
Actually I think this may have it (seems to work ok) - any advice/comments?
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var dragHandle: UIView!
@IBOutlet weak var dragHandleTopConstaint: NSLayoutConstraint!
var lastLocation:CGPoint = CGPointMake(0, 0)
override func viewDidLoad() {
super.viewDidLoad()
// Allow dragging
let pan = UIPanGestureRecognizer(target:self, action:"pan:")
pan.maximumNumberOfTouches = 1
pan.minimumNumberOfTouches = 1
self.dragHandle.addGestureRecognizer(pan)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
func pan(rec:UIPanGestureRecognizer) {
switch rec.state {
case .Began:
self.lastLocation = self.dragHandle.center
case .Changed:
let translation = rec.translationInView(self.dragHandle)
let newLocation : CGPoint = CGPointMake(lastLocation.x, lastLocation.y + translation.y)
self.dragHandleTopConstaint.constant = newLocation.y
default:
()
}
}
}