當我單擊MessageController上的左側欄按鈕時,我將它啓用爲false。然後,我呈現PopUpViewController,並在按鈕上單擊函數removeAnimate()運行。在這個函數中,我想將MessageController左邊的bar按鈕設置爲isEnabled爲true。我已經嘗試過,但不起作用。有人可以幫忙嗎?如何從其他ViewController啓用leftBarButtonItem?
class PopUpViewController: UIViewController {
...
override func viewDidLoad() {
super.viewDidLoad()
self.view.backgroundColor = UIColor.black.withAlphaComponent(0.8)
self.showAnimate()
}
func showAnimate()
{
view.backgroundColor = UIColor.black.withAlphaComponent(0.8)
self.view.transform = CGAffineTransform(scaleX: 1.3, y: 1.3)
self.view.alpha = 0.0;
UIView.animate(withDuration: 0.25, animations: {
self.view.alpha = 1.0
self.view.transform = CGAffineTransform(scaleX: 1.0, y: 1.0)
});
}
func removeAnimate()
{
let messagView = MessageController()
UIView.animate(withDuration: 0.25, animations: {
self.view.transform = CGAffineTransform(scaleX: 1.3, y: 1.3)
self.view.alpha = 0.0;
}, completion:{(finished : Bool) in
if (finished)
{
self.view.removeFromSuperview()
messagView.navigationItem.leftBarButtonItem?.isEnabled = true
}
});
}
lazy var cancleButton: UIButton = {
let button = UIButton(type: .system)
button.translatesAutoresizingMaskIntoConstraints = false
button.setTitle("Cancel", for: UIControlState())
button.titleLabel?.font = UIFont.boldSystemFont(ofSize: 20)
button.tintColor = .white
button.addTarget(self, action: #selector(removeAnimate), for: .touchUpInside)
return button
}()
}
MessageViewController
class MessageController: UITableViewController {
override func viewDidLoad() {
super.viewDidLoad()
navigationItem.leftBarButtonItem = UIBarButtonItem(title: "Logout", style: .plain, target: self, action: #selector(preformSettings))
}
func preformSettings(){
let popViewController = PopUpViewController()
self.addChildViewController(popViewController)
popViewController.view.frame = self.view.frame
self.view.addSubview(popViewController.view)
popViewController.didMove(toParentViewController: self)
navigationItem.leftBarButtonItem?.isEnabled = false
}
}
如何從'MessageController'跳轉到'PopUpViewController'? –
@ Mr.Bistra in func preformSettings() – Moonwalker4z
這意味着沒有segue? –