Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

added bounced and closed callbacks to trayview

  • Loading branch information...
commit 60bbb6505660ba051565aeb142037d1be5635c50 1 parent 91f9c40
@JeremyOT authored
View
2  SlideMenu/TrayView.h
@@ -23,6 +23,8 @@ typedef enum {
@property (nonatomic, assign) TrayPosition trayPosition;
@property (nonatomic) BOOL bouncesOnClose;
@property (nonatomic) NSTimeInterval defaultAnimationDuration;
+@property (nonatomic, copy) void (^closedBlock)();
+@property (nonatomic, copy) void (^bouncedBlock)();
-(void)showInWindow:(UIWindow*)window;
-(void)showInWindow:(UIWindow*)window withDuration:(NSTimeInterval)duration;
View
20 SlideMenu/TrayView.m
@@ -21,6 +21,10 @@ @implementation TrayView
@synthesize trayPosition = _trayPosition;
@synthesize bouncesOnClose = _bouncesOnClose;
@synthesize defaultAnimationDuration = _defaultAnimationDuration;
+@synthesize closedBlock = _closedBlock;
+@synthesize bouncedBlock = _bouncedBlock;
+
+#pragma mark - Lifecycle
- (id)initWithFrame:(CGRect)frame {
if (([super initWithFrame:frame])) {
@@ -41,6 +45,16 @@ - (id)initWithFrame:(CGRect)frame {
return self;
}
+- (void)dealloc {
+ [_slideView release];
+ [_backgroundImageView release];
+ [_closedBlock release];
+ [_bouncedBlock release];
+ [super dealloc];
+}
+
+#pragma mark - Display
+
-(UIImage *)backgroundImage {
return _backgroundImageView.image;
}
@@ -212,6 +226,9 @@ -(void)hideWithDuration:(NSTimeInterval)duration bounce:(BOOL)bounce{
[self removeFromSuperview];
_slideView.clipsToBounds = YES;
_slideView = nil;
+ if (_closedBlock) {
+ _closedBlock();
+ }
}];
};
if (bounce) {
@@ -234,6 +251,9 @@ -(void)hideWithDuration:(NSTimeInterval)duration bounce:(BOOL)bounce{
}
_slideView.frame = frame;
} completion: ^(BOOL completed) {
+ if (_bouncedBlock) {
+ _bouncedBlock();
+ }
closeAnimation();
}];
} else {
View
13 SlideMenuDemo/SlideMenuDemo/SMViewController.m
@@ -51,7 +51,18 @@ - (void)viewDidLoad
NSArray *moreItems = [NSArray arrayWithObjects:
[[[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 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];
[[SlideMenu sharedMenu] addSectionWithName:@"Header 2" items:moreItems];
[[SlideMenu sharedMenuRight] addSectionWithName:@"Header Right 2" items:moreItems];
Please sign in to comment.
Something went wrong with that request. Please try again.