【发布时间】:2017-09-03 21:22:38
【问题描述】:
我在 TabBar 中间有一个带有自定义按钮的 UITabBarController。但是如果我设置hidesBottomBarWhenPushed = true,我会得到一个奇怪的行为。
我在 Swift 3 中以编程方式创建了 UITabBarController。
这是我创建自定义中间按钮的代码:
func setupMiddleButton() {
let menuButton = UIButton(frame: CGRect(x: 0, y: 0, width: 48, height: 48))
var menuButtonFrame = menuButton.frame
menuButtonFrame.origin.y = view.bounds.height - menuButtonFrame.height
menuButtonFrame.origin.x = view.bounds.width/2 - menuButtonFrame.size.width/2
menuButton.frame = menuButtonFrame
menuButton.layer.cornerRadius = menuButtonFrame.height/2
view.addSubview(menuButton)
menuButton.setImage(UIImage(named: "updatemoment"), for: .normal)
menuButton.addTarget(self, action: #selector(menuButtonAction), for: .touchUpInside)
view.layoutIfNeeded()
}
func menuButtonAction() {
let storyboard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
let vc: UINavigationController = storyboard.instantiateViewController(withIdentifier: "NewPostID") as! UINavigationController
self.present(vc, animated: true, completion: nil)
print("segue success")
}
如何解决这个问题?我希望中间按钮留在BottomBar。
提前致谢。
【问题讨论】:
标签: ios swift3 uitabbarcontroller