尝试在 IOS 中创建滑动条菜单
Trying To Create a Slidebar Menu in IOS
我想在我的应用程序中创建一个滑动条菜单(如下图所示)
当我单击那个汉堡包图标时,它应该会显示如下所示的菜单。
我目前正在使用 SWRevealController,这是一个用 Objective C 编写的库。我创建了一个桥接头并导入了 class。这是我目前的设置
我的分支到菜单控制器或 UIViewTable 的初始视图是 SWRevealController,并且转场是 SWRevealViewControllerSegueSetController 的子classes。在我的 Food Item View Controller(存在汉堡包导航的控制器)中,我添加了以下代码来激活滑动条操作。
override func viewDidLoad() {
super.viewDidLoad()
//Creating the slidebar Navigation using SWRevealViewController
if self.revealViewController() != nil {
menuButton.target = self.revealViewController()
menuButton.action = #selector(SWRevealViewController.revealToggle(_:))
self.view.addGestureRecognizer(self.revealViewController().panGestureRecognizer())
}
}
但是,当我点击按钮时,它仍然没有反应。当我对我的其他应用程序执行此操作时,它运行良好。我不确定为什么它在这里不起作用
这是我用作参考的来源:http://www.appcoda.com/sidebar-menu-swift/
查看控制器完整代码
@IBOutlet weak var thumbnail_image: UIImageView!
//@IBOutlet weak var food_detail: UITextView!
@IBOutlet weak var testing: UILabel!
@IBOutlet weak var menuButton: UIBarButtonItem!
var jsonResponseFood: NSArray = NSArray() //API for types of food available
var jsonResponseRecipe: NSArray = NSArray() // API for recipes in food
var selectedFood: foodItem?
var postStr: String?
//Initializing API
let FullRecipeAPIModel = fullRecipeAPIModel()
override func viewDidLoad() {
super.viewDidLoad()
//Creating the slidebar Navigation using SWRevealViewController
if self.revealViewController() != nil {
menuButton.target = self.revealViewController()
menuButton.action = #selector(SWRevealViewController.revealToggle(_:))
self.view.addGestureRecognizer(self.revealViewController().panGestureRecognizer())
}
print(selectedFood?.name as String!)
//testing.text = self.selectedFood?.name
let APIModel = apiModel()
APIModel.delegate = self
FullRecipeAPIModel.delegate = self
APIModel.downloadItems(postString: postStr!)
// Do any additional setup after loading the view.
}
谢谢 Whosebug。
你的代码中的问题是你没有将 SWRevealController 设置为 root view.No 代码明智的情节提要选项可用我们必须再次进行配置。这个图书馆就是这样设计的。因此,如果您按以下方式更改代码,它会非常有效。
if(stat == "login"){
if(responseString == "invalid"){
self.isValid = false;
print(self.isValid)
}
DispatchQueue.main.async(execute: {
if self.checkLogin(data: responseString!) == true {
let storyboard = UIStoryboard(name: "food", bundle: nil)
let controller = storyboard.instantiateViewController(withIdentifier: "foodItemViewController") as! foodItemViewController
let navController = UINavigationController(rootViewController: controller) // Creating a navigation controller with VC1 at the root of the navigation stack.
let appDelegate = UIApplication.shared.delegate as! AppDelegate
let menuView :MenuController = storyboard.instantiateViewController(withIdentifier: "menuBar") as! MenuController
let revealController = SWRevealViewController()
revealController.frontViewController = navController;
revealController.rearViewController = menuView;
appDelegate.window?.rootViewController = revealController
}
else{
//Show alert here
self.showAlert(title: "User Does Not Exist", alertTitle: "Close", message: "");
}
});
}
else{
//CODE COULD BE SIMPLIFIED
DispatchQueue.main.async(execute: {
if(responseString == "duplicate"){
//Show alert here
self.showAlert(title: "User with this email already exist", alertTitle: "Close", message: "Please register with another email address")
}
else{
//Show Food UITable
let storyboard = UIStoryboard(name: "food", bundle: nil)
let controller = storyboard.instantiateViewController(withIdentifier: "entranceFoodController")
/*let navController = UINavigationController(rootViewController: controller) // Creating a navigation controller with VC1 at the root of the navigation stack.*/
let appDelegate = UIApplication.shared.delegate as! AppDelegate
let menuView :MenuController = storyboard.instantiateViewController(withIdentifier: "menuBar") as! MenuController
let revealController = SWRevealViewController()
revealController.frontViewController = controller;
revealController.rearViewController = menuView;
appDelegate.window?.rootViewController = revealController }
});
}
我今天也在研究这个问题,这是使用 SWRevealController 的最佳选择吗,苹果没有内置的方法吗?我很想看到选项,而不是从 Github 中得到一些东西,除非那是我最后的选择。
我想在我的应用程序中创建一个滑动条菜单(如下图所示)
当我单击那个汉堡包图标时,它应该会显示如下所示的菜单。
我目前正在使用 SWRevealController,这是一个用 Objective C 编写的库。我创建了一个桥接头并导入了 class。这是我目前的设置
我的分支到菜单控制器或 UIViewTable 的初始视图是 SWRevealController,并且转场是 SWRevealViewControllerSegueSetController 的子classes。在我的 Food Item View Controller(存在汉堡包导航的控制器)中,我添加了以下代码来激活滑动条操作。
override func viewDidLoad() {
super.viewDidLoad()
//Creating the slidebar Navigation using SWRevealViewController
if self.revealViewController() != nil {
menuButton.target = self.revealViewController()
menuButton.action = #selector(SWRevealViewController.revealToggle(_:))
self.view.addGestureRecognizer(self.revealViewController().panGestureRecognizer())
}
}
但是,当我点击按钮时,它仍然没有反应。当我对我的其他应用程序执行此操作时,它运行良好。我不确定为什么它在这里不起作用
这是我用作参考的来源:http://www.appcoda.com/sidebar-menu-swift/
查看控制器完整代码
@IBOutlet weak var thumbnail_image: UIImageView!
//@IBOutlet weak var food_detail: UITextView!
@IBOutlet weak var testing: UILabel!
@IBOutlet weak var menuButton: UIBarButtonItem!
var jsonResponseFood: NSArray = NSArray() //API for types of food available
var jsonResponseRecipe: NSArray = NSArray() // API for recipes in food
var selectedFood: foodItem?
var postStr: String?
//Initializing API
let FullRecipeAPIModel = fullRecipeAPIModel()
override func viewDidLoad() {
super.viewDidLoad()
//Creating the slidebar Navigation using SWRevealViewController
if self.revealViewController() != nil {
menuButton.target = self.revealViewController()
menuButton.action = #selector(SWRevealViewController.revealToggle(_:))
self.view.addGestureRecognizer(self.revealViewController().panGestureRecognizer())
}
print(selectedFood?.name as String!)
//testing.text = self.selectedFood?.name
let APIModel = apiModel()
APIModel.delegate = self
FullRecipeAPIModel.delegate = self
APIModel.downloadItems(postString: postStr!)
// Do any additional setup after loading the view.
}
谢谢 Whosebug。
你的代码中的问题是你没有将 SWRevealController 设置为 root view.No 代码明智的情节提要选项可用我们必须再次进行配置。这个图书馆就是这样设计的。因此,如果您按以下方式更改代码,它会非常有效。
if(stat == "login"){
if(responseString == "invalid"){
self.isValid = false;
print(self.isValid)
}
DispatchQueue.main.async(execute: {
if self.checkLogin(data: responseString!) == true {
let storyboard = UIStoryboard(name: "food", bundle: nil)
let controller = storyboard.instantiateViewController(withIdentifier: "foodItemViewController") as! foodItemViewController
let navController = UINavigationController(rootViewController: controller) // Creating a navigation controller with VC1 at the root of the navigation stack.
let appDelegate = UIApplication.shared.delegate as! AppDelegate
let menuView :MenuController = storyboard.instantiateViewController(withIdentifier: "menuBar") as! MenuController
let revealController = SWRevealViewController()
revealController.frontViewController = navController;
revealController.rearViewController = menuView;
appDelegate.window?.rootViewController = revealController
}
else{
//Show alert here
self.showAlert(title: "User Does Not Exist", alertTitle: "Close", message: "");
}
});
}
else{
//CODE COULD BE SIMPLIFIED
DispatchQueue.main.async(execute: {
if(responseString == "duplicate"){
//Show alert here
self.showAlert(title: "User with this email already exist", alertTitle: "Close", message: "Please register with another email address")
}
else{
//Show Food UITable
let storyboard = UIStoryboard(name: "food", bundle: nil)
let controller = storyboard.instantiateViewController(withIdentifier: "entranceFoodController")
/*let navController = UINavigationController(rootViewController: controller) // Creating a navigation controller with VC1 at the root of the navigation stack.*/
let appDelegate = UIApplication.shared.delegate as! AppDelegate
let menuView :MenuController = storyboard.instantiateViewController(withIdentifier: "menuBar") as! MenuController
let revealController = SWRevealViewController()
revealController.frontViewController = controller;
revealController.rearViewController = menuView;
appDelegate.window?.rootViewController = revealController }
});
}
我今天也在研究这个问题,这是使用 SWRevealController 的最佳选择吗,苹果没有内置的方法吗?我很想看到选项,而不是从 Github 中得到一些东西,除非那是我最后的选择。