我需要設置此功能的幫助。從第一個視圖控制器中,用戶點擊縮略圖圖像以轉到此視圖控制器,該控制器將全屏顯示圖像。我已經定製了導航欄的外觀,以便它與應用程序的其餘部分看起來不同,所以相同的導航欄未與以前的鏈接關聯。用戶點擊全屏圖像時隱藏導航欄和工具欄?
我已經設法顯示導航欄如何我想要它和所有的按鈕工作,我也希望他們。現在我只想在視圖出現時隱藏導航欄,當用戶點擊,顯示導航欄時,甚至可能會在該過程中將背景顏色從黑色更改爲白色。以下是我有:
var profileImage: UIImage!
var tap = UITapGestureRecognizer()
@IBOutlet var scrollView: UIScrollView!
@IBOutlet var fullSizeImage: UIImageView!
override fun viewWillAppear(animated: Bool) {
self.fullSizeImage.image = profileImage
self.scrollView.minimumZoomScale = 1.0
self.scrollView.maximumZoomScale = 6.0
tap.addTarget(self, action: "tappedScreen")
fullSizeImage.addGestureRecognizer(tap)
fullSizeImage.userInteractionEnabled = true
let navBar = UINavigationBar(frame: CGRectMake(0, 20, self.view.frame.size.width, 44))
navBar.barTintColor = UIColor.whiteColor()
navBar.delegate = self
let navItem = UINavigationItem()
navItem.title = "Profile Image"
let leftButton = UIBarButtonItem(title: "Back", style: UIBarButtonItemStyle.Plain, target: self, action: "cancelButton:")
leftButton.tintColor = UIColor(red: 37/255, green: 94/255, blue: 67/255, alpha: 1.0)
let rightButton = UIBarButtonItem(title: "Gallery", style: UIBarButtonItemStyle.Plain, target: self, action: "galleryButton:")
rightButton.tintColor = UIColor(red: 37/255, green: 94/255, blue: 67/255, alpha: 1.0)
navItem.leftBarButtonItem = leftButton
navItem.rightBarButtonItem = rightButton
navBar.items = [navItem]
self.view.addSubview(navBar)
}
fun tappedScreen() {
print("Tapped Screen")
}
到現在爲止我的調試器輸出「抽頭屏幕」當我點擊,所以我只是在尋找一些代碼,會隱藏自己的導航欄。我嘗試了很多不同的方式,我知道它的將是兩種:
navigationController?.barHideOnTapGestureRecognizer
// OR
navigationController?.hidesBarsOnTap = true
// OR
navigationController?.setNavigationBarHidden(true, animated: true)
但我似乎不能把他們在正確的地方或什麼的,也許是因爲我的自定義導航欄或因爲我有從以前的視圖控制器的自定義segue?我正在使用所有最新版本的swift,xCode等。預先感謝!
感謝您的反饋!不幸的是,這仍然沒有伎倆..我把navigationController?.hidesBarsOnTap = true在viewDidLoad,viewWillAppear和tappedScreen,都沒有這樣做..任何其他建議? – bme003
這個工作!但是..這隻適用於當我將它設置在viewWillAppear和tappedScreen()函數不能改變隱藏的值。我們很近!此外,我需要爲我的底部工具欄最終設置相同的功能。 – bme003
所以我爲不同場景組合了一個小算法,當我想讓navBar隱藏或顯示時。我可以瀏覽並觀看每個場景的工作,但現在唯一不起作用的是navBar.hidden只能工作一次,它不能保持切換。我需要一個解決方法。 – bme003