2015-12-22 166 views
0

我有一個UIScrollViewUIView內的內容。在UIView上,我有一些按鈕用於菜單。一切都很好,直到我旋轉到風景。一旦我旋轉,UIView上的按鈕不能點擊,但頂部的按鈕仍然工作。我假設這是因爲持有按鈕的UIView沒有被調整大小,所以它不響應水龍頭。這可以在三維爆炸圖像中看到(圖4)。我嘗試了所有這些代碼行來嘗試調整大小,按鈕已經工作(代碼因爲我嘗試了不同的組合而被評論)。UIView不改變大小在旋轉Autolayout

override func willRotateToInterfaceOrientation(toInterfaceOrientation: UIInterfaceOrientation, duration: NSTimeInterval) { 
    //hides and displays tab bar on orientation changes 
    if toInterfaceOrientation.isLandscape { 
     tabBarController!.tabBar.hidden = true 


     //self.navigationController!.view.sizeToFit() 
     //self.navigationController!.view.setNeedsLayout() 
     //self.viewForContent.setNeedsLayout() 
     //self.viewForMenuItems.setNeedsLayout() 
     //self.viewForContent.contentSize = CGSizeMake(900, 900) 
     //self.viewForContent.setNeedsLayout()  
    } 
    else if toInterfaceOrientation.isPortrait { 
     tabBarController!.tabBar.hidden = false 

     //self.navigationController!.view.setNeedsLayout() 
     //self.viewForContent.setNeedsLayout() 
     //self.viewForMenuItems.setNeedsLayout() 

     //self.viewForContent.contentSize = CGSizeMake(900, 900) 
     //self.viewForContent.setNeedsLayout() 

    } 
} 

此外,我有這在DidLoad和DidLayoutSubviews。當我註釋掉DidLayoutSubviews按鈕重新工作,但滾動型是沒有大到足以讓我滾動至底部的按鈕時,在景觀

override func viewDidLoad() { 
    super.viewDidLoad() 

    let size = UIScreen.mainScreen().bounds.size 
    viewForContent.contentSize = CGSizeMake(size.width, 458) 

    // Do any additional setup after loading the view. 

} 

override func viewDidLayoutSubviews() { 
    super.viewDidLayoutSubviews() 

    let size = UIScreen.mainScreen().bounds.size 
    viewForContent.contentSize = CGSizeMake(size.width, 458) 
} 

我的信息,我的員工,我的同事,我和居民是在橫向模式下工作的按鈕。我使用autolayout約束來設置視圖。另外,我使用XCode7Swift

任何幫助,將不勝感激

感謝

+1

你知道'willRotateToInterfaceOrientation'已被棄用,對吧? – matt

+1

首先''willRotateToInterfaceOrientation'已被棄用使用'viewWillTransitionToSize'。接下來的事情是,如果您使用自動佈局的界面構建器,則不必直到寫出幀代碼,除非您需要覆蓋它們。必須有自動佈局問題。 「https://iosschool.wordpress.com/2015/10/30/uiscrollview-with-autolayout/」這可能會有幫助 –

回答

0

首先,我設置爲在Kusul在評論上面貼的鏈接概括我的意見(謝謝)。但是,當我這樣做,並將按鈕添加到內容視圖時,它們不會顯示在屏幕旋轉到橫向時,因爲它們離底部不遠,UIScrollView沒有「增長」。

我想通了,我需要添加底部約束到我最後一個按鈕。所以最後一個按鈕現在對頂部和底部有一個約束。這迫使滾動視圖「增長」到適當的大小。然後,我可以消除在didLoad和didLayoutSubviews中設置大小。感謝您的幫助