Created
October 4, 2008 04:10
-
-
Save nickjs/14722 to your computer and use it in GitHub Desktop.
This file contains 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
@implementation LEToolbar : CPView | |
{ | |
CPView _toolbarPart; | |
CPView _stackPart; | |
LEAnimation _toolbarOpenAnimation; | |
LEAnimation _toolbarCloseAnimation; | |
LEAnimation _stackOpenAnimation; | |
LEAnimation _stackCloseAnimation; | |
} | |
- (void)openToolbar:(int)width | |
{ | |
if(!_toolbarOpenAnimation) | |
{ | |
_toolbarOpenAnimation = [[LEPropertyAnimation alloc] initWithView:self property:@"width"]; | |
[_toolbarOpenAnimation setStart:[CPNumber numberWithInt:85]]; | |
[_toolbarOpenAnimation setDuration:0.6]; | |
[_toolbarOpenAnimation setAnimationCurve:CPAnimationEaseInOut]; | |
} | |
[_toolbarOpenAnimation setEnd:[CPNumber numberWithInt:width]]; | |
[_toolbarOpenAnimation startAnimation]; | |
} | |
- (void)closeToolbar:(int)width | |
{ | |
if(!_toolbarCloseAnimation) | |
{ | |
_toolbarCloseAnimation = [[LEPropertyAnimation alloc] initWithView:self property:@"width"]; | |
[_toolbarCloseAnimation setEnd:[CPNumber numberWithInt:85]]; | |
[_toolbarCloseAnimation setDuration:0.6]; | |
[_toolbarCloseAnimation setAnimationCurve:CPAnimationEaseInOut]; | |
} | |
[_toolbarCloseAnimation setStart:[CPNumber numberWithInt:width]]; | |
[_toolbarCloseAnimation startAnimation]; | |
} | |
- (void)openStack:(int)height | |
{ | |
if(!_stackOpenAnimation) | |
{ | |
_stackOpenAnimation = [[LEPropertyAnimation alloc] initWithView:self property:@"height"]; | |
[_stackOpenAnimation setStart:[CPNumber numberWithInt:230]]; | |
[_stackOpenAnimation setDuration:0.6]; | |
[_stackOpenAnimation setAnimationCurve:CPAnimationEaseInOut]; | |
} | |
[_stackOpenAnimation setEnd:[CPNumber numberWithInt:height]]; | |
[_stackOpenAnimation startAnimation]; | |
} | |
- (void)closeStack:(int)height | |
{ | |
if(!_stackCloseAnimation) | |
{ | |
_stackCloseAnimation = [[LEPropertyAnimation alloc] initWithView:self property:@"height"]; | |
[_stackCloseAnimation setEnd:[CPNumber numberWithInt:230]]; | |
[_stackCloseAnimation setDuration:0.6]; | |
[_stackCloseAnimation setAnimationCurve:CPAnimationEaseInOut]; | |
} | |
[_stackCloseAnimation setStart:[CPNumber numberWithInt:height]]; | |
[_stackCloseAnimation startAnimation]; | |
} | |
- (int)width | |
{ | |
return CGRectGetWidth([_toolbarPart frame]); | |
} | |
- (void)setWidth:(int)width | |
{ | |
[_toolbarPart setFrameSize:CGSizeMake(width,CGRectGetHeight([_toolbarPart frame]))]; | |
} | |
- (int)height | |
{ | |
return CGRectGetHeight([_stackPart frame]); | |
} | |
- (void)setHeight:(int)height | |
{ | |
[_stackPart setFrameSize:CGSizeMake(CGRectGetWidth([_stackPart frame]),height)]; | |
} | |
@end |
This file contains 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
//Calling the animations: | |
- (void)openToolbar:(id)sender | |
{ | |
[[LEToolbar defaultToolbar] openStack:800]; | |
[[LEToolbar defaultToolbar] openToolbar:500]; | |
} |
This file contains 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
@implementation LEPropertyAnimation : CPAnimation | |
{ | |
CPView _view; | |
CPString _getPath; | |
CPString _setPath; | |
CPValue _start; | |
CPValue _end; | |
} | |
- (LEAnimation)initWithView:(CPView)aView property:(NSString)keyPath | |
{ | |
self = [super initWithDuration:1.0 animationCurve:CPAnimationLinear]; | |
if(self) | |
{ | |
if([aView respondsToSelector:keyPath]){ | |
_view = aView; | |
_keyPath = keyPath; | |
} else { | |
return null; | |
} | |
} | |
return self; | |
} | |
- (void)setCurrentProgress:(float)progress | |
{ | |
[super setCurrentProgress:progress]; | |
if(_keyPath == 'width' || _keyPath == 'height') | |
progress = (progress * ([_end intValue] - [_start intValue])) + [_start intValue]; | |
[_view setValue:progress forKey:_keyPath]; | |
} | |
- (void)setStart:(id)aValue | |
{ | |
_start = aValue; | |
} | |
- (id)start | |
{ | |
return _start; | |
} | |
- (void)setEnd:(id)aValue | |
{ | |
_end = aValue; | |
} | |
- (id)end | |
{ | |
return _end; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment