I have a UIView
at the bottom of my screen with a UIButton
on top, showing, when I press the button, view slides up with a nice animation.
Everything works fine, now I would like to enable swipe up gesture in the UIButton, so user doesn't actually have to press the button but just slide the finger.
To slide up the view, I just set the frame of it in button action. Now, would be also nice to swipe the view with the finger, something like when you release the view goes up or down, but if you don't release the swipe, the view stays at your finger. Does that make sense?
How could I achieve this?
[UIView animateWithDuration:1.0 animations:^{
self.tableView.contentInset = contentInsets;
self.tableView.scrollIndicatorInsets = contentInsets;
self.sliding.view.frame = CGRectMake(0, 418, 320, 150);
}];
Do you want to swipe the view, or swipe the button?
In either case, what you would do would be to create and configure a UISwipeGestureRecognizer, and attach it to the field that you want to respond to the swipe gesture.
I would suggest attaching the gesture recognizer to the view that's being moved, not to the button. I think it would be confusing to swipe on a button and have it slide a view to the side as a result.
Take a look at the docs on UISwipeGestureRecognizer in Xcode. You'll want to set the direction and number of touches required.
You'll want to create a swipe gesture recognizer with initWithTarget:action:
, then attach it to the view with the UIView method addGestureRecognizer:
. If you are attaching the gesture recognizer to a non-control, you might need to set the userInteractionEnabled flag on the view to YES.