我有一个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/”这可能会有帮助 –