我有5个标签,中心按钮是自定义的,所以我创建了一个UITabBarController类来自定义中心按钮。发生的事情是当我 hidesBottomBarWhenPushed 标签栏变为隐藏时,除了中心自定义按钮仍然可见&甚至没有禁用当我选中
class TabBar: UITabBarController {
@IBOutlet weak var centerButton:UIButton!
override func viewDidLoad() {
super.viewDidLoad()
let nImage = UIImage(named: "infobutton")
let bImage = UIImageView(image: nImage!)
bImage.frame.size = CGSize(width: 50, height: 50)
let cButton: UIButton = UIButton.buttonWithType(UIButtonType.Custom) as UIButton
cButton.autoresizingMask = UIViewAutoresizing.FlexibleRightMargin | UIViewAutoresizing.FlexibleLeftMargin | UIViewAutoresizing.FlexibleTopMargin | UIViewAutoresizing.FlexibleBottomMargin
cButton.frame = CGRectMake(0,0, 50, 50)
cButton.setBackgroundImage(nImage, forState: UIControlState.Normal)
cButton.setBackgroundImage(nImage, forState: UIControlState.Highlighted)
cButton.addTarget(self, action: "buttonPressed:", forControlEvents: UIControlEvents.TouchUpInside)
self.centerButton = cButton
var heightDifference:CGFloat = bImage.frame.size.height - self.tabBar.frame.size.height
if (heightDifference < 0) {
cButton.center = self.tabBar.center;
} else {
var center:CGPoint = self.tabBar.center;
center.y = center.y - heightDifference/2.0;
cButton.center = center
}
self.view.addSubview(cButton)
}
func buttonPressed(sender:UIButton) {
self.selectedIndex = 2
}
}