我有一个滚动视图和背后的图像视图,我用笔尖填充它.我正在使用autolayout.我有一个底层空间可以看到超级视图,还有一个顶层空间可以在两个视图上进行超视图.图像视图完全符合我的要求.对于iphone 5来说,它就是我想要它的地方.而对于其他iphone,它保持在屏幕底部之上,因此它可以正确调整大小.滚动视图在iphone 5上看起来是正确的,但在其他手机上它没有调整大小,所以它向下滚动到应用程序的视图下方.我在日志中收到这些消息:
2012-11-21 10:42:38.576 LCHApp[12604:907] Unable to simultaneously satisfy constraints.
Probably at least one of the constraints in the following list is one you don't want.
Try this: (1) look at each constraint and try to figure out which you don't expect;
(2) find the code that added the unwanted constraint or constraints and fix it.
(Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer
to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints)
"<NSLayoutConstraint:0x1d8ea080 UIScrollView:0x1d8413b0.bottom == UIImageView:0x1d892110.bottom>",
"<NSAutoresizingMaskLayoutConstraint:0x1d8cca10 …Run Code Online (Sandbox Code Playgroud) 我想让AutoLayout UIScrollView与它一起工作,并且我遇到了一些麻烦.这是我做的:
UIScrollView在主视图内添加框架:[top:0,left:0,width:320,height:568]
UIView在UIScrollViewwith frame和bgcolor black中添加"ContentView" :[top:0,left:0,width:320,height:568]
设置UIScrollView约束:[top:0,bottom:0,left:0,right:0]
设置"ContentView"约束:[top:0,bottom:0,left:0,right:0]
对齐"ContentView"中的项目
将主视图bgcolor设置为灰色(查看发生了什么)
以下是问题的屏幕截图:http://imgur.com/P8s9lB0
由于某种原因,约束使内容视图位于屏幕的中间.此外,它向各个方向滚动.我希望内容只能在垂直方向上滚动UITableView,所以我不能这样移动:http://imgur.com/lBCwfAS
我究竟做错了什么?我已经检查了StackOverflow和Google中可以找到的所有教程和答案,并且没有人真正有一个奇怪的问题,所以我正在寻求帮助.
编辑:我还添加了ContentView的宽度和高度作为约束,这也没有帮助.
我使用autolayout UIScrollView来显示对象的一些属性.我从网络服务下载这个信息.scrollview具有恒定的宽度(因为我不希望有垂直滚动行为),并且其子视图使用一组约束来尊重此宽度,但我不能UILabel动态地增加其高度.
我编码所有内容,我使用viewDidLoad选择器来创建子视图...
- (void)viewDidLoad {
[super viewDidLoad];
.
.
.
UILabel *descriptionLabel = [[UILabel alloc] initWithFrame:CGRectZero];
descriptionLabel.translatesAutoresizingMaskIntoConstraints = NO;
descriptionLabel.numberOfLines = 0;
descriptionLabel.lineBreakMode = NSLineBreakByWordWrapping;
descriptionLabel.opaque = YES;
descriptionLabel.backgroundColor = [UIColor clearColor];
descriptionLabel.textColor = [UIColor whiteColor];
descriptionLabel.textAlignment = NSTextAlignmentRight;
descriptionLabel.font = [UIFont appetitoMediumItalicFontWithSize:15.0f];
descriptionLabel.text = NSLocalizedStringFromTable(@"APT_DISH_DETAIL_DESCRIPTION", @"DishDetail", @"Etiqueta que contiene la descripción del platillo");
[descriptionLabel setContentHuggingPriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisVertical];
[self.detailContentScrollView addSubview:descriptionLabel];
self.descriptionLabelS = descriptionLabel;
.
.
.
}
Run Code Online (Sandbox Code Playgroud)
您可以观察self.detailContentScrollView变量,这是IBOulet从视图控制器的笔尖创建的.
然后我使用updateConstraints选择器...... …
我在界面构建器中创建了一个简单的视图设置.以下是它的外观:

视图层次结构很简单:
view
- scrollView
-- label
Run Code Online (Sandbox Code Playgroud)
滚动视图显示为grey背景锚定到其超级视图顶部,前导,尾随和底部,约束为0.
标签以yellow背景显示,并具有所示的约束.此外,该标签具有content hugging priority的1000横向和纵向,它具有content compression resistance priority的1000横向和垂直.
在纵向方向上,标签尺寸正确:

但是,在横向方向上,标签的水平尺寸不正确(我打算用标签填充屏幕的宽度,减少约束插入,如图所示):

如何在横向方向上水平正确地标注此标签?