自定义SWRevealViewController

时间:2015-12-01 02:35:44

标签: swift customization swrevealviewcontroller

我使用SWRevealViewController为我的iOS应用创建了一个幻灯片菜单。现在我想自定义它。我一直在尝试将此教程用作参考http://www.ebc.cat/2015/03/07/customize-your-swrevealviewcontroller-slide-out-menu/。不知道Obj-C我没有取得多大成功。

具体来说,我想设置rearViewRevealDisplacement = 0。有人可以教我如何使用Swift进行自定义吗?

当前代码(最后一行):

   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
    }

1 个答案:

答案 0 :(得分:1)

您应该自定义SWRevealViewController.m文件。在SWRevealViewController.m里面添加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)

并从viewDidLoad

调用此func

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

现在您可以自定义幻灯片菜单,只需更改customizeSlideOutMenu功能中的值