Ios 在弹出vc时在选项卡栏下显示的UITabBar上添加子视图
我有一个简单的选项卡栏项目,我在选项卡栏上添加了一个图像,一开始看起来不错 当pushed=true时,第二个视图从HidesBottomBar的FirstViewController中推送。然后,我隐藏了按钮,该按钮是出于正当理由添加到视图上的,而不是作为子视图添加到选项卡栏上的 一切正常,直到我按下后退按钮,当我取消隐藏视图(或重新创建它)时,显示在选项卡栏下 我应该将showButton()方法放在哪个方法中,以便它再次显示在选项卡栏上 有什么建议吗 CustomTabBarController.swiftIos 在弹出vc时在选项卡栏下显示的UITabBar上添加子视图,ios,swift,uitabbarcontroller,uitabbar,Ios,Swift,Uitabbarcontroller,Uitabbar,我有一个简单的选项卡栏项目,我在选项卡栏上添加了一个图像,一开始看起来不错 当pushed=true时,第二个视图从HidesBottomBar的FirstViewController中推送。然后,我隐藏了按钮,该按钮是出于正当理由添加到视图上的,而不是作为子视图添加到选项卡栏上的 一切正常,直到我按下后退按钮,当我取消隐藏视图(或重新创建它)时,显示在选项卡栏下 我应该将showButton()方法放在哪个方法中,以便它再次显示在选项卡栏上 有什么建议吗 CustomTabBarControl
class CustomTabBarController: UITabBarController {
var bigButton: UIImageView!
func addCenterButton() {
let image = UIImage(named: "bigButtonBackground")
bigButton = UIImageView(image: image)
bigButton.frame = CGRectMake(0.0, 0.0, image!.size.width, image!.size.height);
bigButton.autoresizingMask = .FlexibleRightMargin | .FlexibleLeftMargin | .FlexibleBottomMargin | .FlexibleTopMargin
let heightDifference = image!.size.height - tabBar.frame.size.height
var center = tabBar.center
center.y = center.y - heightDifference/2.0
bigButton.center = center
view.addSubview(bigButton)
}
func hideButton() {
bigButton.hidden = true
}
func showButton() {
bigButton.hidden = false
view.bringSubviewToFront(bigButton)
}
}
class FirstViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
(tabBarController as! CustomTabBarController).addCenterButton()
}
override func viewDidAppear(animated: Bool) {
super.viewDidAppear(animated)
(tabBarController as! CustomTabBarController).showButton()
}
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
let viewController = segue.destinationViewController as! UIViewController
(tabBarController as! CustomTabBarController).hideButton()
viewController.hidesBottomBarWhenPushed = true
}
}
FirstViewController.swift
class CustomTabBarController: UITabBarController {
var bigButton: UIImageView!
func addCenterButton() {
let image = UIImage(named: "bigButtonBackground")
bigButton = UIImageView(image: image)
bigButton.frame = CGRectMake(0.0, 0.0, image!.size.width, image!.size.height);
bigButton.autoresizingMask = .FlexibleRightMargin | .FlexibleLeftMargin | .FlexibleBottomMargin | .FlexibleTopMargin
let heightDifference = image!.size.height - tabBar.frame.size.height
var center = tabBar.center
center.y = center.y - heightDifference/2.0
bigButton.center = center
view.addSubview(bigButton)
}
func hideButton() {
bigButton.hidden = true
}
func showButton() {
bigButton.hidden = false
view.bringSubviewToFront(bigButton)
}
}
class FirstViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
(tabBarController as! CustomTabBarController).addCenterButton()
}
override func viewDidAppear(animated: Bool) {
super.viewDidAppear(animated)
(tabBarController as! CustomTabBarController).showButton()
}
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
let viewController = segue.destinationViewController as! UIViewController
(tabBarController as! CustomTabBarController).hideButton()
viewController.hidesBottomBarWhenPushed = true
}
}
我正在处理一个类似的情况,并最终子类化了
UITabBarController
。在子类“viewdilayoutsubviews
方法中,调用bringSubviewToFront(view:UIView)
并传入位于选项卡栏后面的视图,解决了这个问题。请确保在UITabBarController
的视图中调用此方法。我也有同样的问题。这里有更新吗?