2017-07-19 18 views
0

我的應用程序中的某個屏幕顯示可放大和縮小的全屏UIImageView。然而,問題是導航欄和底部欄在該屏幕阻止UIImageView頂部和底部。我怎樣才能確保酒吧不會阻止內容?如何防止頂部和底部欄阻擋視圖控制器(iOS)中的主要內容

enter image description here

+0

退房'topLayoutGuide'和'bottomLayoutGuide'。答案取決於你如何創建視圖,但這兩個UIViewController屬性是答案。 –

+0

我實際上使用名爲MWPhotoBrowser的庫來創建視圖。像這樣創建視圖控制器:let mygalleryVC = MyGalleryVC(rootViewController:browser) –

回答

0

如果您在上面所示的觀點是在MWPhotoBrowser庫完全建立,那麼你就必須依靠該庫拍攝照片尺寸的護理之一。我看到的唯一選項在他們的代碼,這可能有助於爲:

browser.zoomPhotosToFill = YES; // Images that almost fill the screen will be initially zoomed to fill (defaults to YES) 
browser.alwaysShowControls = NO; // Allows to control whether the bars and controls are always visible or whether they fade away to show the photo full (defaults to NO) 

你可能會與這些設置播放,看看他們是否幫助調整您的視角。

+0

恐怕這些設置什麼都不做。我希望我可以重寫導航控制器中的一些設置來解決問題。我將照片瀏覽器嵌入到自定義導航控制器中。 –

+0

您的自定義導航控制器是否有導航欄或隱藏導航欄,以便您可以看到照片瀏覽器導航欄? – davidethell

0

總之一句話:你可以改變圖層的不透明度屬性,0表示100%隱藏,1是指100%顯示

當圖像視圖顯示在屏幕上,同時改變的導航欄和TabBar的不透明度爲0,變化如果不是,則這些不透明度值爲1。您可以將手勢識別器添加到圖像視圖以更改不透明度。

代碼演示了斯威夫特3 & iOS的10

class DetailNavigationController: UINavigationController { 
    override func viewDidLoad() { 
     super.viewDidLoad() 

     setupViews() 
    } 

    func setupViews() { 
     let detailController = CustomDetailViewController() 
     viewControllers = [detailController] 
     view.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(showOrHideBarView))) 

    } 

    func showOrHideBarView() { 
     UIView.animate(withDuration: 0.4) { 
      self.navigationBar.layer.opacity = self.navigationBar.layer.opacity == 1 ? 0: 1 
      self.tabBarController?.tabBar.layer.opacity = self.tabBarController?.tabBar.layer.opacity == 1 ? 0: 1 
     } 
    } 
} 

class CustomDetailViewController: UIViewController { 
    override func viewDidLoad() { 
     super.viewDidLoad() 

     setupViews() 
    } 

    func setupViews() { 
     view.backgroundColor = UIColor.green 
    } 
} 
相關問題