revealViewController 委托不起作用
Posted
技术标签:
【中文标题】revealViewController 委托不起作用【英文标题】:revealViewController delegate doesn't work 【发布时间】:2017-10-26 07:55:54 【问题描述】:我正在使用 SWReveal 库来创建侧边菜单,我的目标是每当用户单击菜单栏时,它将打开侧边菜单并禁用前视图,并使前视图变为黑色且不透明。
我需要按菜单汉堡栏返回前视图
我试图模仿的例子
我的代码
import UIKit
class ViewController: UIViewController, SWRevealViewControllerDelegate
@IBOutlet var menuBarBurger: UIBarButtonItem!
override func viewDidLoad()
super.viewDidLoad()
revealViewController().delegate = self
setupSideMenu()
func setupSideMenu()
if revealViewController() != nil
menuBarBurger.target = self.revealViewController()
menuBarBurger.action = #selector(SWRevealViewController.revealToggle(_:))
revealViewController().rearViewRevealWidth = 300
view.addGestureRecognizer(self.revealViewController().panGestureRecognizer())
// This is the part where the background will turn blur and so on.
func revealController(revealController: SWRevealViewController!, willMoveToPosition position: FrontViewPosition)
let tagId = 8009
if revealController.frontViewPosition == FrontViewPosition.right
let lock = self.view.viewWithTag(tagId)
UIView.animate(withDuration: 0.25, animations:
lock?.alpha = 0
, completion: (finished: Bool) in
lock?.removeFromSuperview()
)
lock?.removeFromSuperview()
else if revealController.frontViewPosition == FrontViewPosition.left
let lock = UIView(frame: self.view.bounds)
lock.autoresizingMask = [.flexibleWidth, .flexibleHeight]
lock.tag = tagId
lock.alpha = 0
lock.backgroundColor = UIColor.black
lock.addGestureRecognizer(UITapGestureRecognizer(target: self.revealViewController(), action: #selector(SWRevealViewController.revealToggle(_:))))
self.view.addSubview(lock)
UIView.animate(withDuration: 0.5, animations:
lock.alpha = 0.333
)
故事板
tagid(以防万一)
我应该怎么做,才能实现相同的设计?
【问题讨论】:
【参考方案1】:您尚未将代理设置为self
revealViewController().delegate = self
假设revealViewController()
是SWRevealViewController
类型并且是您要显示的ViewController。
【讨论】:
我已经添加了那行,但似乎它不起作用,甚至没有触发委托。 你能分享revealViewController()
的代码吗?
任何成功,同样的问题
revealViewController()
的声明是什么?以上是关于revealViewController 委托不起作用的主要内容,如果未能解决你的问题,请参考以下文章
self.revealViewController 变为 nil 并且 SWRevealViewController 菜单在从某个 VC 转回 SWRevelViewController 后不显示