Showing posts with label crash on MMDrawer on sliding. Show all posts
Showing posts with label crash on MMDrawer on sliding. Show all posts

Tuesday, 24 September 2013

Customization of MMDrawerController | Notification badge over MMDrawer on left-side | Crash on slide

#import <QuartzCore/QuartzCore.h>

 - (void)setupNavigationBar:(id)target withNotificationBadge:(NSUInteger)badgeValue{
UIViewController *ctr = (UIViewController *)target; CGRect leftFrame = CGRectMake(0,0,30,44) UIView *view = [[UIView alloc] initWithFrame:leftFrame]; // logo Button UIButton *logoBtn = [UIButton buttonWithType:UIButtonTypeCustom]; logoBtn.frame = CGRectMake(0,7,30,30); logoBtn.userInteractionEnabled = YES; [logoBtn setBackgroundImage:[UIImage imageNamed:@"YOUR_IMAGE_NAME"]forState:UIControlStateNormal]; [logoBtn addTarget:ctr action:@selector(leftDrawerButtonPress:) forControlEvents:UIControlEventTouchUpInside]; [view addSubview:logoBtn]; // Notification Badge if (badgeValue > 0){ NSInteger armLength = 20; UILabel *badgeLbl = [[UILabel alloc] init]; badgeLbl.frame = CGRectMake(25, 2, armLength, armLength); badgeLbl.text = [NSString stringWithFormat:@"%i",badgeValue]; badgeLbl.layer.cornerRadius = armLength/2; badgeLbl.layer.masksToBounds = YES; badgeLbl.backgroundColor = [UIColor redColor];        badgeLbl.textColor = [UIColor whiteColor];        badgeLbl.font = [UIFont systemFontOfSize:11.0f];        badgeLbl.textAlignment = UITextAlignmentCenter;        [view addSubview:badgeLbl];     } UIBarButtonItem *leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:view];   ctr.navigationItem.leftBarButtonItem = leftBarButtonItem; }
Drawer Button click function To use instance of MMDrawerController, you just need to do #import "UIViewController+MMDrawerController.h"
- (void)leftDrawerButtonPress:(id)sender{
    [self.mm_drawerController toggleDrawerSide:MMDrawerSideLeft animated:YES completion:nil];
}
In MMDrawerController.m file 

other fixes:
1. Orientation in Portrait mode only instead of supporting all orientations they provide by default.
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation{
  return  (toInterfaceOrientation == UIInterfaceOrientationPortrait);
}
2. Drawer sliding either one of side
you must handle, drawerSide is not Equal to MMDrawerSideNone check, find given below:
-(void)updateDrawerVisualStateForDrawerSide:(MMDrawerSide)drawerSide percentVisible:(CGFloat)percentVisible{
  if(self.drawerVisualState){
       if(drawerSide != MMDrawerSideNone)
            self.drawerVisualState(self,drawerSide,percentVisible);
  } else if(self.shouldStretchDrawer){
        [self applyOvershootScaleTransformForDrawerSide:drawerSide percentVisible:percentVisible];
    }
}
output:

55: Badge value
AJ is an icon with white background.