ฉันกำลังพยายามหาวิธีซ่อนแถบแท็บในแอพที่รวดเร็วของ iOS ฉันไม่สนใจเกี่ยวกับแอนิเมชั่นแฟนซีหรืออะไรเลย ฉันสามารถใส่บางอย่างในฟังก์ชัน ViewDidLoad () ได้
ฉันกำลังพยายามหาวิธีซ่อนแถบแท็บในแอพที่รวดเร็วของ iOS ฉันไม่สนใจเกี่ยวกับแอนิเมชั่นแฟนซีหรืออะไรเลย ฉันสามารถใส่บางอย่างในฟังก์ชัน ViewDidLoad () ได้
คำตอบ:
คุณสามารถใช้สิ่งนี้ในViewDidLoad()
วิธีการของคุณ
self.tabBarController?.tabBar.hidden = true
สำหรับ Swift 3.0, 4.0, 5.0 :
self.tabBarController?.tabBar.isHidden = true
หรือคุณสามารถเปลี่ยนตำแหน่ง z ของแถบแท็บด้วยวิธีนี้:
self.tabBarController?.tabBar.layer.zPosition = -1
และหากคุณต้องการแสดงอีกครั้ง:
self.tabBarController?.tabBar.layer.zPosition = 0
คำตอบที่ยอมรับใช้งานได้ แต่การเปลี่ยนไปใช้มุมมองอื่นมีภาพเคลื่อนไหวที่กระตุก (ภาพเคลื่อนไหวแถบแท็บ)
ต้องการเพิ่มแม้ว่าโซลูชันของ Kalpesh จะทำงานได้อย่างสมบูรณ์แบบสำหรับฉัน แต่ฉันพบว่าตัวควบคุมมุมมองทุกตัวมีแอตทริบิวต์สำหรับ hidesBottomBarWhenPushed (ดูสตอรี่บอร์ด) หากคุณต้องการซ่อนแถบแท็บคุณควรทำเครื่องหมายที่ และมันจะทำงานได้ดี
อัปเดต: ฉันไม่แน่ใจว่านี่เป็นสิ่งที่ทราบหรือไม่ แต่นี่คือสิ่งที่หน้าเอกสารของ Apple ระบุว่า:
ฉันคิดว่านี่หมายความว่าคุณต้องตั้งค่าพื้นฐานของ hidesBottomBarWhenPushed ที่ตัวควบคุมมุมมองด้านบนสุด (ตัวแรกบนสแต็กการนำทาง) เมื่อคุณตั้งค่าเป็นจริงคุณสามารถเปลี่ยนเป็นเท็จหรือจริงสำหรับตัวควบคุมมุมมองอื่นบน ซ้อนกัน. แต่ถ้าค่า hidesBottomBarWhenPushed ของคอนโทรลเลอร์มุมมองบนสุดของคุณเป็นเท็จจะไม่แสดงแถบแท็บสำหรับคอนโทรลเลอร์อื่น ๆ บนสแต็กการนำทาง
ก่อนที่จะผลักดันชุด controller.hidesBottomBarWhenPushed = true
let objCreateEventVC = CreateEventVC()
objCreateEventVC.hidesBottomBarWhenPushed = true
self.navigationController?.pushViewController(objCreateEventVC, animated: false)
setViewControllers
ไม่จำเป็นต้องตั้งค่าคุณสมบัติ isHidden ของ tabBar
เพียงไปที่ ViewController (ใน StoryBoard) -> ตัวตรวจสอบคุณสมบัติ -> ในส่วน 'View Controller' ให้เลือกช่องทำเครื่องหมาย 'Hide Bottom Bar on Push' การทำงานนี้เหมือนมีเสน่ห์
หากคุณไปทาง 'isHidden' คุณจะต้องจัดการหลายอย่างเช่นทำให้ปรากฏขึ้นอีกครั้งเมื่อคุณย้อนกลับและลบพื้นที่ว่างด้านล่างออกหลังจากซ่อน tabBar
Hide Bottom Bar on Push
มีภาพเคลื่อนไหวที่ไม่พึงประสงค์ imo
สวิฟต์ 3.
self.tabBarController?.tabBar.isHidden = true
คุณยังสามารถตั้งค่าเป็นส่วนขยาย (ใช้คำตอบ Dharmesh Kheni)
extension UITabBar {
func tabsVisiblty(_ isVisiblty: Bool = true){
if isVisiblty {
self.isHidden = false
self.layer.zPosition = 0
} else {
self.isHidden = true
self.layer.zPosition = -1
}
}
นี่เป็นวิธีทางโปรแกรมสำหรับ Swift 4.0, 4.1, 4.2, 5.0 และใหม่กว่า >:
tabBarController?.hidesBottomBarWhenPushed = true
หรือ
hidesBottomBarWhenPushed = true
ในการซ่อน navigationBar และ tabBar ฉันใช้ฟังก์ชันถัดไป:
var tabBarHeight : CGFloat!
func fullScreenAction(){
if navigationController?.isNavigationBarHidden ?? false {
//Show navigationBar
navigationController?.setNavigationBarHidden(false, animated: false)
//Show tabBar
tabBarController?.tabBar.isHidden = false
//Update the height of tabBar
if (!(tabBarController?.tabBar.frame.size.height.isEqual(to: 0))!) {
tabBarHeight = self.tabBarController?.tabBar.frame.size.height
}
tabBarController?.tabBar.frame.size.height = tabBarHeight
} else {
//Hide navigationBar
navigationController?.setNavigationBarHidden(true, animated: false)
//Hide tabBar
tabBarController?.tabBar.isHidden = true
//Update the height of tabBar
tabBarHeight = tabBarController?.tabBar.frame.size.height
tabBarController?.tabBar.frame.size.height = 0
}
}
เมื่อการวางแนวหน้าจอเปลี่ยนความสูงของแถบแถบก็เปลี่ยนไปด้วยดังนั้นฉันจึงใช้ฟังก์ชันถัดไปเพื่อออกจากการแสดงเต็มหน้าจอเพื่อปรับขนาดความสูง:
override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
super.viewWillTransition(to: size, with: coordinator)
if navigationController?.isNavigationBarHidden ?? false {
navigationController?.setNavigationBarHidden(false, animated: false)
tabBarController?.tabBar.isHidden = false
}
}
ฉันหวังว่ามันจะเป็นประโยชน์สำหรับคุณ
vc.hidesBottomBarWhenPushed = true
ควรทำงาน อย่าแสดงและซ่อนแถบแท็บด้วยตนเอง