2015-12-22 169 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中设置大小。感谢您的帮助