0

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.

Dinesh Raja
  • 8,501
  • 5
  • 42
  • 81
user1120008
  • 1,005
  • 4
  • 13
  • 27

2 Answers2

0

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.

Community
  • 1
  • 1
ohho
  • 50,879
  • 75
  • 256
  • 383
0

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.

John
  • 1,519
  • 3
  • 13
  • 24