Created
August 15, 2016 12:22
-
-
Save hudinwal/c5707c430625b94cb1bf794f31d0266d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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