2015-12-01 67 views
0

我使用SWRevealViewController爲我的iOS應用程序創建滑出菜單。現在我想定製它。我一直在嘗試使用本教程作爲參考http://www.ebc.cat/2015/03/07/customize-your-swrevealviewcontroller-slide-out-menu/。不知道Obj-C,我沒有取得太多的成功。我想設置rearViewRevealDisplacement = 0。有人可以教我如何使用Swift進行自定義嗎?自定義SWRevealViewController

當前代碼(最後一行):

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

您應該定製SWRevealViewController.m文件。從viewDidLoad中

 
-(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)

,並調用本功能

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

現在你可以定製你的滑出式菜單,只是改變customizeSlideOutMenu FUNC

+0

更多的信息值:內部SWRevealViewController.m添加FUNC: http://www.ebc.cat/2015/03/07/customize-your-swrevealviewcontroller-slide-out-menu/ –