您的位置:首页 > 移动开发 > IOS开发

iOS之隐藏/显示tabbar

2016-03-31 15:49 543 查看
func setTabBarHidden(flag:Bool!){
//将view的frame放大到全屏,就把TabBar变相隐藏了,不会出现黑色区域。
if UIApplication.sharedApplication().keyWindow?.rootViewController?.isKindOfClass(UITabBarController.self) == true{
let tabVC : UITabBarController = UIApplication.sharedApplication().keyWindow?.rootViewController as! UITabBarController
// if tabVC.tabBar.hidden != flag{
debugPrint("UITabBarController hidden \(tabVC.tabBar.hidden)")

let tab = tabVC.view//self.tabBarController?.view
if tab?.subviews.count < 2 {
return
}
var tmpView : UIView!
if tab?.subviews[0].isKindOfClass(UITabBar.self) == true {
tmpView = tab?.subviews[1]
}else{
tmpView = tab?.subviews[0]
}
if flag == true{
tmpView.frame = (tab?.bounds)!
tmpView.frame = CGRectMake(tmpView.bounds.origin.x,  tmpView.bounds.origin.y,  tmpView.bounds.size.width, tmpView.bounds.size.height + self.tabBarController!.tabBar.frame.size.height);

}else{
tmpView.frame = CGRectMake((tab?.bounds.origin.x)!, (tab?.bounds.origin.y)!, (tab?.bounds.size.width)!, (tab?.bounds.size.height)!)

}
debugPrint("UITabBarController tmpView \(tmpView)")
//                tabVC.view.backgroundColor = UIColor.whiteColor()
tabVC.tabBar.hidden = flag
}
//}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: