自定义 SWRevealViewController
Posted
技术标签:
【中文标题】自定义 SWRevealViewController【英文标题】:Customize SWRevealViewController 【发布时间】:2015-12-01 02:35:44 【问题描述】:我使用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】:您应该自定义 SWRevealViewController.m 文件。在 SWRevealViewController.m 中添加 func:
-(无效)customSlideOutMenu // INITIAL APPEARANCE:配置菜单和内容视图的初始位置 self.frontViewPosition = FrontViewPositionLeft; // FrontViewPositionLeft(仅内容)、FrontViewPositionRight(菜单和内容)、FrontViewPositionRightMost(仅菜单),请参阅库文档中的其他内容... self.rearViewRevealWidth = 150.0f; // 显示多少菜单(默认 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];
[self customizeSlideOutMenu];
现在您可以自定义滑出式菜单,只需更改 customizeSlideOutMenu func 中的值
【讨论】:
更多信息:ebc.cat/2015/03/07/…以上是关于自定义 SWRevealViewController的主要内容,如果未能解决你的问题,请参考以下文章