选择菜单项后如何显示viewController?
How to bring out the viewController after menu item is selected?
我正在尝试在 select 菜单中的一项之后显示 viewcontroller。目前,当我按下某些东西时,它只会改变页面,但它会卡在右侧。怎么弄出来。
这是我写的代码。
class ContainerVC: UIViewController {
var sideMenuOpen = false
@IBOutlet weak var mainView: UIView!
override func viewDidLoad() {
super.viewDidLoad()
NotificationCenter.default.addObserver(self,
selector: #selector(toggleSideMenu),
name: NSNotification.Name("ToggleSideMenu"),
object: nil)
}
@IBOutlet weak var sideMenuConstraint: NSLayoutConstraint!
@objc func toggleSideMenu() {
if sideMenuOpen {
sideMenuOpen = false
sideMenuConstraint.constant = -270
} else {
sideMenuOpen = true
sideMenuConstraint.constant = 0
}
UIView.animate(withDuration: 0.3) {
self.view.layoutIfNeeded()
}
}
}
这就是我在 SideMenuVC 中写的内容
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
print(indexPath.row)
// NotificationCenter.default.post(name: NSNotification.Name ("ToggleSideMenu"), object: nil)
switch indexPath.row {
case 0: NotificationCenter.default.post(name: NSNotification.Name ("ShowProfile"), object: nil)
case 8: //signs out of Firebase
try? Auth.auth().signOut()
//signs out of Facebook
FBSDKAccessToken.setCurrent(nil)
let main = UIStoryboard(name: "Main", bundle: nil)
let second = main.instantiateViewController(withIdentifier: "loginPage")
self.present(second, animated: true, completion: nil)
default: break
//https://www.youtube.com/watch?v=Hl_Re_KLhcY
}
}
这是我在 HomeVC 中写的
@IBAction func menuButton() {
print("Toggle Side Menu")
NotificationCenter.default.post(name: NSNotification.Name("ToggleSideMenu"), object: nil)
}
我希望 selected 页面出来。
只需将 NotificationCenter.default.post(name: NSNotification.Name ("ToggleSideMenu"), object: nil)
添加到您的 didSelectRowAt
我正在尝试在 select 菜单中的一项之后显示 viewcontroller。目前,当我按下某些东西时,它只会改变页面,但它会卡在右侧。怎么弄出来。
这是我写的代码。
class ContainerVC: UIViewController {
var sideMenuOpen = false
@IBOutlet weak var mainView: UIView!
override func viewDidLoad() {
super.viewDidLoad()
NotificationCenter.default.addObserver(self,
selector: #selector(toggleSideMenu),
name: NSNotification.Name("ToggleSideMenu"),
object: nil)
}
@IBOutlet weak var sideMenuConstraint: NSLayoutConstraint!
@objc func toggleSideMenu() {
if sideMenuOpen {
sideMenuOpen = false
sideMenuConstraint.constant = -270
} else {
sideMenuOpen = true
sideMenuConstraint.constant = 0
}
UIView.animate(withDuration: 0.3) {
self.view.layoutIfNeeded()
}
}
}
这就是我在 SideMenuVC 中写的内容
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
print(indexPath.row)
// NotificationCenter.default.post(name: NSNotification.Name ("ToggleSideMenu"), object: nil)
switch indexPath.row {
case 0: NotificationCenter.default.post(name: NSNotification.Name ("ShowProfile"), object: nil)
case 8: //signs out of Firebase
try? Auth.auth().signOut()
//signs out of Facebook
FBSDKAccessToken.setCurrent(nil)
let main = UIStoryboard(name: "Main", bundle: nil)
let second = main.instantiateViewController(withIdentifier: "loginPage")
self.present(second, animated: true, completion: nil)
default: break
//https://www.youtube.com/watch?v=Hl_Re_KLhcY
}
}
这是我在 HomeVC 中写的
@IBAction func menuButton() {
print("Toggle Side Menu")
NotificationCenter.default.post(name: NSNotification.Name("ToggleSideMenu"), object: nil)
}
我希望 selected 页面出来。
只需将 NotificationCenter.default.post(name: NSNotification.Name ("ToggleSideMenu"), object: nil)
添加到您的 didSelectRowAt