I'm making an iOS8 app using Swift. I'd like the user to be able to use gestures to reveal certain parts of the interface. So for example, the user slides their finger up and the view they slid their finger up moves out of the way, following their finger to reveal another view underneath.
What I'd like is a gesture to give a result similar to the notification box that you can pull down from the top of the screen. I've been looking at the documentation and I can't seem to find a suitable gesture.
I saw one called UISwipeGestureRecogniser, but the only problem is, it doesn't follow your finger, it simply runs a function when I slide my finger up / down.
Here's the documentation page: https://developer.apple.com/documentation/uikit/uigesturerecognizer
You're looking for the UIPanGestureRecognizer. You'll find the Apple Documentation here.
Here's a sample handler that will move a view with your finger. In Interface Builder, add a
UIPanGestureRecognizer
to a view that you want to be able to drag. Set the delegate to yourViewController
. Set the action to this action:Swift 2.X:
Swift 3:
Of course, you can add the
UIPanGestureRecognizer
programmatically:In
viewDidLoad
for yourViewController
, create the recognizer and add it to the view you want to be able to drag: