UITabBarController
をサブクラス化していて、タブバーの中央にボタンを追加しようとしています。最初はうまくアップを示しています。私は私のTableViewControllerで項目を選択するとTabBarの前にUIButtonを置いておきます
はその後、それが表示されたまま:
さらに、私は戻ってTableViewControllerに移動するとき、タブバーの後ろに表示されます。
これは私がボタンを追加するために使用しているコードです:
class PhotoTabBarController: UITabBarController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
addPhotoButton()
}
// ...
func addPhotoButton() {
let button = UploadButton(frame: CGRect(x: 0, y: 0, width: 60, height: 60))
// Start of code to center button in the tab bar
let heightDifference = button.frame.size.height - self.tabBar.frame.size.height;
// if the height of the center button is less than the height of the tab bar...
if (heightDifference < 0) {
// center the button inside the tab bar
button.center = self.tabBar.center;
} else {
var center = self.tabBar.center;
center.y = center.y - heightDifference/2.0 - 5
button.center = center;
}
self.view.addSubview(button)
self.view.bringSubview(toFront: button)
}
}
ボタンの外観をdraw(_ rect: CGRect)
機能で作成されます。
セルが選択されたときにボタンがタブバーに隠れるようにするために何かできますか?TableViewControllerにナビゲートすると正面に移動しますか?
にこのボタンを追加しますか? – Poles
このボタンはUIApplication.shared.delegate?.window –