iOS 8 autolayout,VFL和margin等于或大于

iOS 8 autolayout,VFL和margin等于或大于,第1张

概述我在iOS 8中遇到了VFL的限制问题,而在6和7这里就可以了.这是约束: H:|-margin-[_imageView]-(=>margin)-[_label]-margin-| _imageView_and _label都可以获得正确的固有宽度,并且边距按预期增长.我想实现 |-[_imageView]-------------------------------[some text]-| 我在iOS 8中遇到了VFL的限制问题,而在6和7这里就可以了.这是约束:
H:|-margin-[_imageVIEw]-(=>margin)-[_label]-margin-|

_imageVIEw_and _label都可以获得正确的固有宽度,并且边距按预期增长.我想实现

|-[_imageVIEw]-------------------------------[some text]-||-[_imageVIEw]---------------------------[a larger text]-||-[_imageVIEw]-----------------------[a very large text]-||-[_imageVIEw]-[a very very very very very very larg...]-|

它是可视的,但它引发了一个破坏的约束异常:

Will attempt to recover by breaking constraint <NSLayoutConstraint:0x7b856ee0 H:[UIImageVIEw:0x7b8ef1f0]-(>=12)-[UILabel:0x7b8e7c60'Test']>

印刷_autolayoutTrace之后没有歧义.

但是,如果约束只涉及标签,那根本就没有问题:

H:|-margin-[_label1]-(=>margin)-[_label2]-margin-|

以下步骤可以解决问题:

更改约束删除> =并添加优先级:

H:|-margin-[_imageVIEw]-(margin@750)-[_label]-margin-|

设置_imageVIEw的拥挤优先级

[_imageVIEw setContentHuggingPriority:UILayoutPriorityDefaultHigh forAxis:UILayoutConstraintAxisHorizontal];

设置_label的抗压缩性

[_label setContentCompressionResistancePriority:UILayoutPriorityDefaultLow forAxis:UILayoutConstraintAxisHorizontal];

有了这些规则,任何平台都没有问题.所有这些在iOS 8上都是必要的吗?这是一个错误还是我做错了?

谢谢.

解决方法 我从头开始开始项目,这里是我的代码(实际工作正常):
UIVIEw *topVIEw = [[UIVIEw alloc] initWithFrame:CGRectMake(0,320,200)];topVIEw.backgroundcolor = [UIcolor redcolor];topVIEw.translatesautoresizingMaskIntoConstraints = NO;UIImageVIEw *imageVIEw = [[UIImageVIEw alloc] initWithFrame:CGRectMake(20,20,40,160)];imageVIEw.backgroundcolor = [UIcolor greencolor];imageVIEw.translatesautoresizingMaskIntoConstraints = NO;[topVIEw addSubvIEw:imageVIEw];self.label = [[UILabel alloc] initWithFrame:CGRectMake(80,80,200,32)];self.label.backgroundcolor = [UIcolor yellowcolor];self.label.text = @"some text";self.label.translatesautoresizingMaskIntoConstraints = NO;[topVIEw addSubvIEw:self.label];self.tableVIEw.tableheaderVIEw = topVIEw;NSDictionary *vIEws = @{@"imageVIEw":imageVIEw,@"label":self.label};NSArray *constraints = [NSLayoutConstraint constraintsWithVisualFormat:@"H:|-margin-[imageVIEw(40)]-(>=margin)-[label]-margin-|" options:0 metrics:@{@"margin": @30} vIEws:vIEws];NSArray *imageConstraints = [NSLayoutConstraint constraintsWithVisualFormat:@"V:|-20-[imageVIEw(160)]-20-|" options:0 metrics:nil vIEws:vIEws];NSArray *textConstraints = [NSLayoutConstraint constraintsWithVisualFormat:@"V:|-40-[label]" options:0 metrics:nil vIEws:vIEws];NSArray *topConstraints = [NSLayoutConstraint constraintsWithVisualFormat:@"H:[topVIEw(320)]" options:0 metrics:nil vIEws:NSDictionaryOfVariableBindings(topVIEw)];[topVIEw addConstraints:constraints];[topVIEw addConstraints:imageConstraints];[topVIEw addConstraints:textConstraints];[topVIEw addConstraints:topConstraints];

我认为你的主要问题是你不会关闭翻译自动化的MaskIntoConstraints来生成UIVIEw-Encapsulated-Layout(我在iOs8之前从未见过).我没有找到一个记录好的地方,但是有关于这个约束的问题很多.

我也创建了github回购,所以你可以自己尝试:https://github.com/Nikita2k/constraintsTest

此外,您可以看一下WWDC2014视频 – 表和集合视图中的新功能(〜20分钟).有一些信息,您现在可以看到UIVIEw-Encapsulated-Layout问题,但稍后会被修复.此外,您可以尝试使用rowHeight,因为故事板(或xib)中的所有ios8 tableVIEw都应显式设置

self.tableVIEw.rowHeight = UItableVIEwautomaticDimension

我不确定,会在这个特殊情况下是否有帮助,但也请试试!

总结

以上是内存溢出为你收集整理的iOS 8 autolayout,VFL和margin等于大于全部内容,希望文章能够帮你解决iOS 8 autolayout,VFL和margin等于或大于所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1095706.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-28
下一篇 2022-05-28

发表评论

登录后才能评论

评论列表(0条)

保存