【问题标题】:UIView to stick at bottom of UIScrollViewUIView 粘在 UIScrollView 的底部
【发布时间】:2012-10-03 20:55:36
【问题描述】:
所以我在 UIViewController 的 UIView 中有一个 UIScrollView,我在其中添加了一个 UIView,并且我希望它始终保持在底部,无论方向如何变化。所以我有以下内容:
问题是当我旋转到横向时,滚动视图内容大小高度肯定会大于框架高度,因此它会向下滚动。但是,我想贴在底部的这个 UIView 并没有粘住。无论方向如何变化,我如何让它始终粘在底部。
当我禁用 UIScrollView 自动调整子视图时,此 UIView 会粘在底部,但旋转时宽度不会调整
【问题讨论】:
标签:
iphone
objective-c
ios
ipad
【解决方案1】:
您必须根据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
}
}
【解决方案2】:
您应该尝试通过以下方式使用自动调整大小的蒙版
yourview.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin;
使用编码或在 IB 中添加上、左、下和右边距的灵活性。
或者根据您的要求在 willRotateToInterfaceOrientation 方法中放置视图。