I'm trying to achieve the following effect. I have a view which can be in two different states - collapsed and expanded). See screenshots for what I have in mind:
Transition between these states should be triggered by panning gesture - user panned down view gets expanded, user panned up - view gets collapsed.
I can achieve this by implementing custom gesture recognizer in the init section of my view subclass:
UIPanGestureRecognizer* recognizer = [[UIPanGestureRecognizer alloc] initWithTarget: self action: @selector(panned:)];
recognizer.delegate = self;
[self addGestureRecognizer: recognizer];
And then detecting proper vertical pan gesture:
- (void)panned:(UIPanGestureRecognizer*)gestureRecognizer
{
static CGPoint lastPoint;
if (gestureRecognizer.state == UIGestureRecognizerStateBegan) {
lastPoint = [gestureRecognizer locationInView: self];
return;
}
if (gestureRecognizer.state == UIGestureRecognizerStateEnded) {
if (p.y > lastPoint.y && self.expanded == NO) {
[self toggle];
}
else if (p.y < lastPoint.y && self.expanded == YES)
{
[self toggle];
}
}
}
Then based on self.expanded
property I layout subviews and change frame accordingly. Everything works more or less ok. The only issue I have is - I'd like to show transition between two states as user panning his finger - so basically view should start expanding gradually back and forth (if user pans back and forth) and then come to the expanded state when gesture is complete.
What's the easiest way to do this?