I'd like a custom gesture so that if the user slides his/her finger up from the bottom of the screen it displays a scroll view that occupies the bottom fourth of the screen. Similarly, to close the view, the user slides his/her finger downwards off the screen. I am mostly having trouble figuring out how to connect the gesture with the animation so that the view slides up and down as the user moves his/her finger.
-
1And what have you tried so far? – Peter Sarnowski Feb 29 '12 at 05:54
-
I implemented the custom gesture and the scroll view. I can make it "magically" appear/disappear. I just don't know how to move the view along with a user's finger. – user1120008 Mar 01 '12 at 04:54
2 Answers
Assume you have two views, self.view
and self.scrollView
. self.scrollView
is a sub-view inside self.view
.
Then place self.scrollView
offscreen.
Register drag
events for both views:
[self.view addTarget:self action:@selector(mainViewMoved:withEvent:) forControlEvents:UIControlEventTouchDragInside];
[self.scrollView addTarget:self action:@selector(scrollViewMoved:withEvent:) forControlEvents:UIControlEventTouchDragInside];
Do whether view movement required in mainViewMoved:withEvent
(bring up scrollView) and scrollViewMoved:withEvent
(move itself up/down) handlers based on the touch movements.
More info in this question.
Check out UIResponder (superclass of UIView). You'll need to implement the following in your base view and your scrollview (for the down swipe) or just your scrollview if there is a "handle" visible when it is hidden:
– touchesBegan:withEvent:
– touchesMoved:withEvent:
– touchesEnded:withEvent:
– touchesCancelled:withEvent:
Record where the touch started to compute how far they moved their finger, and adjust the frame of the scroll view accordingly. When they lift their finger (touchesEnded) determine if they have passed some threshold (say 20 pixels) and if so slide up/down your scrollview.

- 1,519
- 3
- 13
- 24