0
我有一個幻燈片菜單,當我按下我的導航欄中的菜單按鈕時顯示它自己。關閉它可以通過點擊背景或菜單本身來完成。在這個視圖中,我有幾個項目,其中一個是用戶配置文件按鈕。當我按下此按鈕時,我希望菜單自行關閉,然後立即打開用戶配置文件視圖控制器。這就是爲什麼我首先調用handleDismiss()然後設置需要打開的視圖Swift - 從幻燈片菜單中打開UIViewController
但是,它一直告訴我視圖不在窗口層次結構中。我知道問題是什麼(視圖堆棧),但我無法讓它正常工作。我應該如何解決這個問題?
RootViewController的 - >的HomeController(的TabBar索引0) - >滑入式菜單 - > UserProfileController
按鈕打開控制器
profileCell.profileButton.addTarget(self, action: #selector(handleUserProfile(sender:)), for: .touchUpInside)
功能
func handleDismiss() {
UIView.animate(withDuration: 0.5) {
self.blackView.alpha = 0
if let window = UIApplication.shared.keyWindow {
self.collectionView.frame = CGRect(x: 0, y: window.frame.height, width: self.collectionView.frame.width, height: self.collectionView.frame.height)
}
}
}
func handleUserProfile(sender: UIButton) {
handleDismiss()
let userProfileController = UserProfileController()
openProfileController(userProfileController)
}
func openProfileController(_ controller: UIViewController) {
present(controller, animated: false, completion: nil)
}