UIView粘在UIScrollView的底部

所以我在UIViewController的UIView里面有一个UIScrollView,里面添加了一个UIView,而且我希望它总是坚持在底部而不pipe方向的变化。 所以我有以下几点:

在这里输入图像说明

问题是,当我旋转到横向时,滚动视图的内容大小高度肯定会比框架高度大,因此它向下滚动。 然而,这个UIView,我想坚持在底部不坚持。 我如何做到这一点,以便它始终坚持底部,无论方向的变化。

当我禁用UIScrollView自动调整子视图,这个UIView坚持到底部,但宽度不调整时旋转

你将不得不根据orientations调整框架见下面的例子 –

 -(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration { if(toInterfaceOrientation == UIInterfaceOrientationPortrait || toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown) { //set your portrait frame here and also the content size of scrollView } else { //set your Landscape frame here and also the content size of scrollView } } 

您应该尝试使用以下方式使用自动resize的蒙版

 yourview.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin; 

使用编码或在IB中添加顶部,左侧,底部和右侧的余量灵活性。

或者按照您的要求在willRotateToInterfaceOrientation方法中放置视图。