Skip to content

Commit

Permalink
added bounced and closed callbacks to trayview
Browse files Browse the repository at this point in the history
  • Loading branch information
JeremyOT committed Mar 28, 2012
1 parent 91f9c40 commit 60bbb65
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
2 changes: 2 additions & 0 deletions SlideMenu/TrayView.h
Expand Up @@ -23,6 +23,8 @@ typedef enum {
@property (nonatomic, assign) TrayPosition trayPosition; @property (nonatomic, assign) TrayPosition trayPosition;
@property (nonatomic) BOOL bouncesOnClose; @property (nonatomic) BOOL bouncesOnClose;
@property (nonatomic) NSTimeInterval defaultAnimationDuration; @property (nonatomic) NSTimeInterval defaultAnimationDuration;
@property (nonatomic, copy) void (^closedBlock)();
@property (nonatomic, copy) void (^bouncedBlock)();


-(void)showInWindow:(UIWindow*)window; -(void)showInWindow:(UIWindow*)window;
-(void)showInWindow:(UIWindow*)window withDuration:(NSTimeInterval)duration; -(void)showInWindow:(UIWindow*)window withDuration:(NSTimeInterval)duration;
Expand Down
20 changes: 20 additions & 0 deletions SlideMenu/TrayView.m
Expand Up @@ -21,6 +21,10 @@ @implementation TrayView
@synthesize trayPosition = _trayPosition; @synthesize trayPosition = _trayPosition;
@synthesize bouncesOnClose = _bouncesOnClose; @synthesize bouncesOnClose = _bouncesOnClose;
@synthesize defaultAnimationDuration = _defaultAnimationDuration; @synthesize defaultAnimationDuration = _defaultAnimationDuration;
@synthesize closedBlock = _closedBlock;
@synthesize bouncedBlock = _bouncedBlock;

#pragma mark - Lifecycle


- (id)initWithFrame:(CGRect)frame { - (id)initWithFrame:(CGRect)frame {
if (([super initWithFrame:frame])) { if (([super initWithFrame:frame])) {
Expand All @@ -41,6 +45,16 @@ - (id)initWithFrame:(CGRect)frame {
return self; return self;
} }


- (void)dealloc {
[_slideView release];
[_backgroundImageView release];
[_closedBlock release];
[_bouncedBlock release];
[super dealloc];
}

#pragma mark - Display

-(UIImage *)backgroundImage { -(UIImage *)backgroundImage {
return _backgroundImageView.image; return _backgroundImageView.image;
} }
Expand Down Expand Up @@ -212,6 +226,9 @@ -(void)hideWithDuration:(NSTimeInterval)duration bounce:(BOOL)bounce{
[self removeFromSuperview]; [self removeFromSuperview];
_slideView.clipsToBounds = YES; _slideView.clipsToBounds = YES;
_slideView = nil; _slideView = nil;
if (_closedBlock) {
_closedBlock();
}
}]; }];
}; };
if (bounce) { if (bounce) {
Expand All @@ -234,6 +251,9 @@ -(void)hideWithDuration:(NSTimeInterval)duration bounce:(BOOL)bounce{
} }
_slideView.frame = frame; _slideView.frame = frame;
} completion: ^(BOOL completed) { } completion: ^(BOOL completed) {
if (_bouncedBlock) {
_bouncedBlock();
}
closeAnimation(); closeAnimation();
}]; }];
} else { } else {
Expand Down
13 changes: 12 additions & 1 deletion SlideMenuDemo/SlideMenuDemo/SMViewController.m
Expand Up @@ -51,7 +51,18 @@ - (void)viewDidLoad
NSArray *moreItems = [NSArray arrayWithObjects: NSArray *moreItems = [NSArray arrayWithObjects:
[[[SlideMenuItem alloc] initWithTitle:@"Item 4" block:block accessoryView:accView] autorelease], [[[SlideMenuItem alloc] initWithTitle:@"Item 4" block:block accessoryView:accView] autorelease],
[[[SlideMenuItem alloc] initWithTitle:@"Item 5" block:block accessoryType:UITableViewCellAccessoryNone icon:nil textColor:[UIColor lightGrayColor] backgroundColor:nil] autorelease], [[[SlideMenuItem alloc] initWithTitle:@"Item 5" block:block accessoryType:UITableViewCellAccessoryNone icon:nil textColor:[UIColor lightGrayColor] backgroundColor:nil] autorelease],
[[[SlideMenuItem alloc] initWithTitle:@"Item 6" block:block accessoryType:UITableViewCellAccessoryNone icon:nil textColor:nil backgroundColor:[UIColor darkGrayColor]] autorelease], [[[SlideMenuItem alloc] initWithTitle:@"Item 6" block:^(SlideMenuItem *item){
[[SlideMenu sharedMenuRight] setBouncedBlock:^(){
NSLog(@"Bounced: %@", item.title);
[[SlideMenu sharedMenuRight] setBouncedBlock:nil];
}];
[[SlideMenu sharedMenuRight] setClosedBlock:^(){
NSLog(@"Closed: %@", item.title);
[[SlideMenu sharedMenuRight] setClosedBlock:nil];
}];
NSLog(@"Clicked: %@", item.title);
return YES;
}accessoryType:UITableViewCellAccessoryNone icon:nil textColor:nil backgroundColor:[UIColor darkGrayColor]] autorelease],
nil]; nil];
[[SlideMenu sharedMenu] addSectionWithName:@"Header 2" items:moreItems]; [[SlideMenu sharedMenu] addSectionWithName:@"Header 2" items:moreItems];
[[SlideMenu sharedMenuRight] addSectionWithName:@"Header Right 2" items:moreItems]; [[SlideMenu sharedMenuRight] addSectionWithName:@"Header Right 2" items:moreItems];
Expand Down

0 comments on commit 60bbb65

Please sign in to comment.