Skip to content

Instantly share code, notes, and snippets.

@hudinwal
Created August 15, 2016 12:22
Show Gist options
  • Save hudinwal/c5707c430625b94cb1bf794f31d0266d to your computer and use it in GitHub Desktop.
Save hudinwal/c5707c430625b94cb1bf794f31d0266d to your computer and use it in GitHub Desktop.
private(set) lazy var swipeDownGesture: UISwipeGestureRecognizer = {
let swipeGesture = UISwipeGestureRecognizer(target: self, action: #selector(ViewController.handleSwipeGestures(_:)))
swipeGesture.direction = .Down
return swipeGesture
}()
private(set) lazy var swipeUpGesture: UISwipeGestureRecognizer = {
let swipeGesture = UISwipeGestureRecognizer(target: self, action: #selector(ViewController.handleSwipeGestures(_:)))
swipeGesture.direction = .Up
return swipeGesture
}()
func handleSwipeGestures(sender : UISwipeGestureRecognizer) {
setMainViewExpanded(sender.direction == .Down, animated: true)
}
func setMainViewExpanded(expanded: Bool, animated: Bool) {
let topInset = pullDownTableView.contentInset.top
let yOffset = expanded ? -topInset : -topOffset
pullDownTableView.setContentOffset(CGPointMake(0, yOffset), animated: true)
}
override func viewDidLoad() {
super.viewDidLoad()
// Add gestures
view.addGestureRecognizer(swipeUpGesture)
view.addGestureRecognizer(swipeDownGesture)
// Create and add the pull down table view
self.view.addSubview(pullDownTableView)
//Set background color to contrasting color
view.backgroundColor = UIColor.darkGrayColor()
pullDownTableView.backgroundColor = UIColor.clearColor()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment