0

I used SWRevealViewController to create a slideout menu for my iOS app. Now I would like to customize it. I've been trying to use this tutorial as a reference http://www.ebc.cat/2015/03/07/customize-your-swrevealviewcontroller-slide-out-menu/. Without knowing Obj-C I haven't had much success.

Specifically, I would like to set rearViewRevealDisplacement = 0. Can someone teach me how to customize using Swift?

Current code (last line):

   if self.revealViewController() != nil {
        slideoutBtn.target = self.revealViewController()
        slideoutBtn.action = Selector("rightRevealToggle:")
        self.view.addGestureRecognizer(self.revealViewController().panGestureRecognizer()) //swipe
        self.view.addGestureRecognizer(self.revealViewController().tapGestureRecognizer()) //tap close
        self.revealViewController().rearViewRevealDisplacement = 0
    }
jkw224
  • 51
  • 1
  • 6

1 Answers1

1

You should to customize SWRevealViewController.m file. Inside SWRevealViewController.m add func:

-(void) customizeSlideOutMenu{
    // INITIAL APPEARANCE: Configure the initial position of the menu and content views
    self.frontViewPosition = FrontViewPositionLeft; // FrontViewPositionLeft (only content), FrontViewPositionRight(menu and content), FrontViewPositionRightMost(only menu), see others at library documentation...
    self.rearViewRevealWidth = 150.0f; // how much of the menu is shown (default 260.0)

// TOGGLING OVERDRAW: Configure the overdraw appearance of the content view while dragging it
self.rearViewRevealOverdraw = 0.0f; // how much of an overdraw can occur when dragging further than 'rearViewRevealWidth' (default 60.0)
self.bounceBackOnOverdraw = NO; // If YES the controller will bounce to the Left position when dragging further than 'rearViewRevealWidth' (default YES)

// TOGGLING MENU DISPLACEMENT: how much displacement is applied to the menu when animating or dragging the content
self.rearViewRevealDisplacement = 60.0f; // (default 40.0)

// TOGGLING ANIMATION: Configure the animation while the menu gets hidden
self.toggleAnimationType = SWRevealToggleAnimationTypeSpring; // Animation type (SWRevealToggleAnimationTypeEaseOut or SWRevealToggleAnimationTypeSpring)
self.toggleAnimationDuration = 1.0f; // Duration for the revealToggle animation (default 0.25)
self.springDampingRatio = 1.0f; // damping ratio if SWRevealToggleAnimationTypeSpring (default 1.0)

// SHADOW: Configure the shadow that appears between the menu and content views
self.frontViewShadowRadius = 10.0f; // radius of the front view's shadow (default 2.5)
self.frontViewShadowOffset = CGSizeMake(0.0f, 2.5f); // radius of the front view's shadow offset (default {0.0f,2.5f})
self.frontViewShadowOpacity = 0.8f; // front view's shadow opacity (default 1.0)
self.frontViewShadowColor = [UIColor darkGrayColor]; } // front view's shadow color (default blackColor) 

and call this func from viewDidLoad

- (void)viewDidLoad{ [super viewDidLoad]; [self customizeSlideOutMenu]; }

Now you can customize your slide-out menu, just change values in customizeSlideOutMenu func