我似乎无法在当前Tabar控制器上方放置自定义按钮。尝试了几种方法,但这是管理最远的方法。该按钮可以完美地适应选项卡栏,但位于当前选项卡栏控制器上方。不能将它放在上面。任何帮助,将不胜感激。
let menuButton = UIButton(frame: CGRect.zero)
在视图加载时设置按钮。
override func viewDidLoad() {
super.viewDidLoad()
setupMiddleButton()
当前标签栏控制器之后和iphone大小之后的调整按钮
}
func setupMiddleButton() {
let numberOfItems = CGFloat((tabBarController?.tabBar.items!.count)!)
let tabBarItemSize = CGSize(width: tabBarController!.tabBar.frame.width / numberOfItems, height: tabBarController!.tabBar.frame.height)
menuButton.frame = CGRect(x: 0, y: 0, width: tabBarItemSize.width, height: tabBarController!.tabBar.frame.size.height)
var menuButtonFrame = menuButton.frame
menuButtonFrame.origin.y = self.view.bounds.height - menuButtonFrame.height - self.view.safeAreaInsets.bottom
menuButtonFrame.origin.x = self.view.bounds.width/2 - menuButtonFrame.size.width/2
menuButton.frame = menuButtonFrame
menuButton.backgroundColor = UIColor.green
self.view.addSubview(menuButton)
self.view.layoutIfNeeded()
}
尝试放置在当前的标签栏控制器上
override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
menuButton.frame.origin.y = self.view.bounds.height - menuButton.frame.height - self.view.safeAreaInsets.bottom
}