Created
April 17, 2013 22:18
-
-
Save pita5/5408226 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CGPoint _firstLocation; | |
CGFloat _startY, _yMinValue = 74.0f, _yFullSize, _yExtraSpace; | |
- (void)panRecognizerAction:(UIPanGestureRecognizer *)recognizer | |
{ | |
CGPoint location = [recognizer locationInView:self]; | |
if (recognizer.state == UIGestureRecognizerStateBegan) | |
{ | |
_startY = self.frame.size.height; | |
_firstLocation = location; | |
_yFullSize = 130; | |
_yExtraSpace = 100.0f; | |
} | |
CGFloat newHeight = _startY - (_firstLocation.y - location.y); | |
if (newHeight < _yMinValue) newHeight = _yMinValue; | |
BOOL overlimit = newHeight > _yFullSize; | |
if (overlimit) | |
{ | |
//width of the area the finger can pan after the menu width | |
CGFloat overlimitWidth = _yFullSize + _yExtraSpace; | |
//we take the position of the finger in this area as a percentage | |
CGFloat overlimitProgress = 1-((overlimitWidth-newHeight)/_yExtraSpace); | |
CGFloat easeOutFactor = atan(overlimitProgress); | |
newHeight = _yFullSize + (_yExtraSpace*easeOutFactor); | |
} | |
if (recognizer.state != UIGestureRecognizerStateEnded && | |
recognizer.state != UIGestureRecognizerStateFailed && | |
recognizer.state != UIGestureRecognizerStateCancelled) | |
{ | |
self.frame = CGRectMake(0, 0, self.frame.size.width, newHeight); | |
} | |
if (recognizer.state == UIGestureRecognizerStateEnded) | |
{ | |
CGPoint velocity = [recognizer velocityInView:self]; | |
if (newHeight > 170) | |
{ | |
[self openToFull:velocity.y]; | |
} | |
else | |
{ | |
if (velocity.y < 0) | |
{ | |
[self openToMin:velocity.y]; | |
} | |
else | |
{ | |
[self openToFull:velocity.y]; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment