这是链接到视图控制器的非常基本的视图。该视图具有单个UILabel,该UILabel放置有编码约束。该代码实际上可以正确运行,但是控制台正在注册约束冲突,并且我无法弄清楚代码的哪一部分正在创建冲突。
LocationView.m文件
#import "LocationView.h"
@implementation LocationView
@synthesize locationTitle;
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
[self setBackgroundColor: [UIColor blueColor]];
locationTitle = [[UILabel alloc]init];
[locationTitle setTranslatesAutoresizingMaskIntoConstraints:NO];
locationTitle.backgroundColor = [UIColor whiteColor];
[self addSubview:locationTitle];
NSDictionary *viewLocationTitle = NSDictionaryOfVariableBindings(locationTitle);
[self addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[locationTitle]|"
options:0
metrics:0
views:viewLocationTitle]];
[self addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-[locationTitle(50)]|"
options:0
metrics:0
views:viewLocationTitle]];
- (void)updateConstraints {
[super updateConstraints];
}
@end
控制台错误
Unable to simultaneously satisfy constraints.
(
"<NSLayoutConstraint:0x109510990 V:|-(NSSpace(20))-[UILabel:0x10950b660] (Names: '|':LocationView:0x10950acc0 )>",
"<NSLayoutConstraint:0x109510c10 V:[UILabel:0x10950b660(50)]>",
"<NSLayoutConstraint:0x109510c60 V:[UILabel:0x10950b660]-(0)-| (Names: '|':LocationView:0x10950acc0 )>",
"<NSAutoresizingMaskLayoutConstraint:0x108f3ae00 h=--& v=--& V:[LocationView:0x10950acc0(568)]>"
)
我认为您是在说要使其高50点并固定在超级视图的顶部和底部(在标签的前后都包含|)。
尝试将垂直约束更改为
@"V:|-[locationTitle(50)]"
或者,您可以为这些约束之一添加较低的优先级,但是我想这就是您的意思。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句