我有一個UIScrollView
與UIView
內的內容。在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
約束來設置視圖。另外,我使用XCode7
和Swift
。
任何幫助,將不勝感激
感謝
你知道'willRotateToInterfaceOrientation'已被棄用,對吧? – matt
首先''willRotateToInterfaceOrientation'已被棄用使用'viewWillTransitionToSize'。接下來的事情是,如果您使用自動佈局的界面構建器,則不必直到寫出幀代碼,除非您需要覆蓋它們。必須有自動佈局問題。 「https://iosschool.wordpress.com/2015/10/30/uiscrollview-with-autolayout/」這可能會有幫助 –