gpt4 book ai didi

swift - 自定义 SWRevealViewController

转载 作者:行者123 更新时间:2023-11-30 10:09:13 25 4
gpt4 key购买 nike

我用了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
}

最佳答案

您应该自定义 SWRevealViewController.m 文件。在 SWRevealViewController.m 中添加函数:

-(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 调用此函数

- (void)viewDidLoad{
[ super viewDidLoad];
[自定义SlideOutMenu];
}

现在您可以自定义滑出菜单,只需更改customizeSlideOutMenu 函数中的值即可

关于swift - 自定义 SWRevealViewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34011643/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com