gpt4 book ai didi

ios - SWRevealViewController 滑动手势不起作用

转载 作者:可可西里 更新时间:2023-10-31 23:44:44 27 4
gpt4 key购买 nike

您好,我已经在 swift 中集成了 swrevealview Controller 。

我在应用程序委托(delegate)中编写了以下代码。

let frontView = ViewController(nibName: "ViewController", bundle: nil)
let rearView = LeftViewController(nibName : "LeftViewController", bundle :nil)

var frontNavigationController = UINavigationController(rootViewController: frontView)
var rearNavigationController = UINavigationController(rootViewController: rearView)

menuSlider = SWRevealViewController(rearViewController: rearNavigationController, frontViewController: frontNavigationController)
menuSlider?.delegate = self

let rightView = LeftViewController(nibName : "RightViewController", bundle :nil)

menuSlider?.rightViewController = rightView

self.window?.rootViewController = menuSlider
self.window?.backgroundColor = UIColor.whiteColor()
self.window?.makeKeyAndVisible()

我写的正面图

 var revealController:SWRevealViewController  = self.revealViewController()
self.view.addGestureRecognizer(revealViewController().panGestureRecognizer())
self.view.addGestureRecognizer(revealViewController().tapGestureRecognizer())

如演示所示。我看过很多建议在 View 上添加手势的帖子。

我不确定我做错了什么。请帮助我解决问题。

谢谢

最佳答案

我能想到的一件事是,当涉及到您的代码时,您没有在任何地方存储对前后 View Controller 的强引用。它基本上会在执行离开方法体后立即被释放。在您的情况下,这样的事情可以解决问题:

Class myClass { 

// Declaration
var frontNC : UINavigationController!
var rearNC : UINavigationController!

...
func myFunction() {

// Usage
self.frontNC = UINavigationController(rootViewController: frontView)
self.readNC = UINavigationController(rootViewController: rearView)

// Note* there is no need to store ViewControllers because those
// are retained by UINavigationController by default. The only
// exception is if you want to do something with them later obviously :)
}
}

虽然它会渲染,但它会产生一整套问题,而根据我的经验,手势识别器是最难跟踪的。

您可以阅读有关 ARC 工作原理的更多详细信息 in the Apple Documentation ,我认为没有人能比那里写的更好地解释它了:)

关于ios - SWRevealViewController 滑动手势不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31427667/

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