我一直得到'无法同时满足约束'的例外(Xcode 5,iOS 7,设备和模拟器),其中列表中的一个约束是这样的:
"<NSLayoutConstraint:0x165b23d0 'UIView-Encapsulated-Layout-Width'
H:[StoryPlayerCell:0x165affc0(0)]>"
我自己没有设置这个约束.它也不是NSAutoresizingMaskLayoutConstraint.但是它来自哪里?我怎么能摆脱它呢?
我不知道.我'UIView-Encapsulated-Layout-Width'在Apple的文档中找不到任何相关内容.即便是谷歌搜索也没有任何回报.
有什么建议?
PS:我在UICollectionView一个自定义子类中使用这个单元格UICollectionViewFlowLayout.也许这'Encapsulated-Layout'部分与此有关?
ios autolayout uicollectionview nslayoutconstraint uicollectionviewlayout
Apple文档建议使用autolayout设置Today Extensions的高度.
如果窗口小部件具有要显示的其他内容,则可以依赖"自动布局"约束来适当调整窗口小部件的高度.如果不使用自动布局,则可以使用UIViewController属性preferredContentSize指定窗口小部件的新高度.
但是,我见过的每个示例和教程最终都会使用preferredContentSize.
我通过autolayout设置高度的所有尝试都会导致违反约束的警告.
我开始使用新的xcode模板和一个全新的扩展模板.我添加的唯一内容TodayViewController.m是:
- (UIEdgeInsets)widgetMarginInsetsForProposedMarginInsets:(UIEdgeInsets)defaultMarginInsets {
    return UIEdgeInsetsMake(0, 0, 0, 0);
}
注意:如果我只使用默认边距,我仍会遇到此问题.
我约束标签高度,将标签置于容器中心,并将容器高度限制为与标签高度相同:

这应该导致一个标签在指定的高度填充容器,没有约束冲突.相反,我得到一个约束冲突:
2014-09-28 10:27:39.254 TodayExtension[61090:2672196] 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 …我正在制作测试应用程序,所以在我的tableviewCell故事板中我有imageView和webView(用于显示html文本).我为imageView设置了top/left/right/height = 200的约束,它们之间的间距= 5,webView的左/右/ bot,所以我想以编程方式计算我的webView高度,然后更改单元格的高度来拉伸我的webView.但我得到了这个:
无法同时满足约束.
可能至少下列列表中的一个约束是您不想要的约束.
试试这个:
(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 & fix it. (Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property
translatesAutoresizingMaskIntoConstraints) 
(
    "<NSLayoutConstraint:0x7fd6f3773f90 V:[UIImageView:0x7fd6f3773e90(200)]>",
    "<NSLayoutConstraint:0x7fd6f3774280 UIImageView:0x7fd6f3773e90.top == UITableViewCellContentView:0x7fd6f3462710.topMargin>",
    "<NSLayoutConstraint:0x7fd6f3774320 V:[UIImageView:0x7fd6f3773e90]-(5)-[UIWebView:0x7fd6f3462800]>",
    "<NSLayoutConstraint:0x7fd6f3774370 UITableViewCellContentView:0x7fd6f3462710.bottomMargin == UIWebView:0x7fd6f3462800.bottom>",
    "<NSLayoutConstraint:0x7fd6f375ee40 'UIView-Encapsulated-Layout-Height' V:[UITableViewCellContentView:0x7fd6f3462710(205)]>"
)
有什么建议?
刚开始学习iOS AutoLayout,界面构建器非常直接,但是当我尝试在代码上存档相同的东西时
    [self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-(==2)-[_nextKeyboardButton]-(==2)-[_numPadButton]-(==2)-[_spaceButton]-(==2)-[_returnButton]-(==2)-|" options:0 metrics:0 views:NSDictionaryOfVariableBindings(_nextKeyboardButton,_numPadButton,_spaceButton,_returnButton)]];
它提出了一个例外,
无法同时满足约束.
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:0x6000000966c0 H:|-(2)-[UIButton:0x7fe4f1d1c760'Next']   (Names: '|':UIInputView:0x7fe4f1f04d00 )>", …我将水平UICollectionView固定到的所有边缘UITableViewCell。集合视图中的项目是动态调整大小的,我想使表视图的高度等于最高的集合视图单元格的高度。
视图的结构如下:
UITableView
UITableViewCell
UICollectionView
UICollectionViewCell
UICollectionViewCell
UICollectionViewCell
class TableViewCell: UITableViewCell {
    private lazy var collectionView: UICollectionView = {
        let collectionView = UICollectionView(frame: self.frame, collectionViewLayout: layout)
        return collectionView
    }()
    var layout: UICollectionViewFlowLayout = {
        let layout = UICollectionViewFlowLayout()
        layout.estimatedItemSize = CGSize(width: 350, height: 20)
        layout.scrollDirection = .horizontal
        return layout
    }()
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        let nib = UINib(nibName: String(describing: CollectionViewCell.self), bundle: nil)
        collectionView.register(nib, forCellWithReuseIdentifier: CollectionViewCellModel.identifier)
        addSubview(collectionView)
        // (using SnapKit)
        collectionView.snp.makeConstraints …我正在尝试将自动布局合并到我的UITableViewHeaderFooterView子类中.这个课程非常基础,只有两个标签.这是完整的子类:
@implementation MBTableDetailStyleFooterView
static void MBTableDetailStyleFooterViewCommonSetup(MBTableDetailStyleFooterView *_self) {
    UILabel *rightLabel = [[UILabel alloc] init];
    _self.rightLabel = rightLabel;
    rightLabel.translatesAutoresizingMaskIntoConstraints = NO;
    [_self.contentView addSubview:rightLabel];
    UILabel *leftLabel = [[UILabel alloc] init];
    _self.leftLabel = leftLabel;
    leftLabel.translatesAutoresizingMaskIntoConstraints = NO;
    [_self.contentView addSubview:leftLabel];
    NSDictionary *views = NSDictionaryOfVariableBindings(rightLabel, leftLabel);
    NSArray *horizontalConstraints = [NSLayoutConstraint constraintsWithVisualFormat:@"|-10-[leftLabel]-(>=10)-[rightLabel]-10-|" options:0 metrics:nil views:views];
    [_self.contentView addConstraints:horizontalConstraints];
    // center views vertically in super view
    NSLayoutConstraint *leftCenterYConstraint = [NSLayoutConstraint constraintWithItem:leftLabel attribute:NSLayoutAttributeCenterY relatedBy:NSLayoutRelationEqual toItem:_self.contentView attribute:NSLayoutAttributeCenterY multiplier:1 constant:0];
    [_self.contentView addConstraint:leftCenterYConstraint];
    NSLayoutConstraint *rightCenterYConstraint = [NSLayoutConstraint constraintWithItem:rightLabel attribute:NSLayoutAttributeCenterY relatedBy:NSLayoutRelationEqual toItem:_self.contentView attribute:NSLayoutAttributeCenterY …关于UITableView单元格和节页眉/页脚的自动布局存在许多堆栈溢出问题,这些问题涉及用于使其组件具有正确大小的UIView-Encapsulated-Layout-Width约束UITableView:
这些约束的目的似乎非常清楚 - 它们允许UITableView并且还UICollectionView与约束布局接口并传递关于大单元(和其他组件)应该如何的规范.
大多数问题似乎是人们有一组必需的约束,这些约束与这些封装约束不兼容,也需要大小0.最可行的答案似乎是降低用户定义约束的优先级,999以便框架可以否决它们.
然而-我感兴趣的理解是为什么被UITableView需要的宽度0为自己的观点吗?这是一个错误吗?或者是不正确使用的结果?或者它是否完美无缺?
0如果细胞从无到有扩展,有时高度限制是有意义的.降低优先级是处理此问题的好方法.但是,为什么会在细胞中得到一个宽的0?
我有一个包含多行标签的UITableViewCell子类,我希望单元格根据该标签的内容动态调整大小.我知道iOS 8引入了基于AutoLayout约束的自动调整大小单元,我已经在SO上找到了几个这样的例子,但我仍然在正确实现这种行为方面遇到一些麻烦.
这是我的updateConstraints实现:
- (void)updateConstraints {
    [super updateConstraints];
    [self addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-10-[_nameLabel(==20)]-10-[_tweetLabel]" options:0 metrics:nil views:NSDictionaryOfVariableBindings(_nameLabel, _tweetLabel)]];
    [self addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:[_avatarView]-10-[_nameLabel]-10-|" options:0 metrics:nil views:NSDictionaryOfVariableBindings(_avatarView, _nameLabel)]];
    [self addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:[_nameLabel]-10-[_tweetLabel]-10-|" options:0 metrics:nil views:NSDictionaryOfVariableBindings(_nameLabel, _tweetLabel)]];
    [self addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:[_avatarView]-10-[_tweetLabel]-10-|" options:0 metrics:nil views:NSDictionaryOfVariableBindings(_avatarView, _tweetLabel)]];
    [self addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-10-[_avatarView(==45)]" options:0 metrics:nil views:NSDictionaryOfVariableBindings(_avatarView)]];
    [self addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-10-[_avatarView(==45)]" options:0 metrics:nil views:NSDictionaryOfVariableBindings(_avatarView)]];
}
在表视图控制器中,我将行高设置为UITableViewAutomaticDimension(我也设置了估计的行高).在运行时,我得到一系列自动布局错误,并且所有表格视图单元格几乎完全重叠.
自动布局冲突在以下约束之间:
V:|-(10)-[_nameLabel]V:[_nameLabel(20)]V:[_nameLabel]-(10)-[_tweetLabel]V:[_tweetLabel]-(10)-|V:[cell(44)]我怀疑最后一个约束,"UIView-Encapsulated-Layout-Height",强制高度为44,是问题的原因,但我不太确定它来自哪里,所以希望有人可以解释一下问题.
我一直在努力装配一个UIImageView显示可变宽度和高度的图像Aspect Fill.单元格高度不适应新的高度UIImageView并保持其高度.
视图的层次结构就是这样
我在XCode自动布局中尝试了这些场景:
UIImageView => Height为remove at build timeIntrinsic Value的UIImageView到placeholderIntrinsic Value为每一个UIImageView,ContentView并UITableViewCell给placeholder有了这些组合中的任何一个,我得到了这个观
http://i.stack.imgur.com/Cw7hS.png
蓝线代表单元格边界(边界),绿色代表UIImageView边框(边界).在这个例子中有四个单元格,第一个和第三个单元格没有图像,第二个和第四个单元格具有相同的图像(溢出没有图像的图像).
我的应用程序有一个UITableView,其行根据类大小具有最小高度约束.具体来说,行中"任意"的最小高度为45,"常规"(即iPad)的最小高度为65.我确保45高度约束只安装在"any-any"中,而65高度约束仅安装在"常规常规"中.
我得到了"无法同时满足约束".由于iOS添加的UIView-Encapsulated-Layout-Height约束,在运行iOS 8.3的iPad mini上运行时发出警告.我已经阅读了这个SO问题,但我认为这个问题没有得到解决.
以下是冲突中的约束:
"<NSLayoutConstraint:0x19116b00 V:|-(0)-[UILabel:0x19115fd0'text']   (Names: '|':UITableViewCellContentView:0x19115f00 )>",
"<NSLayoutConstraint:0x19116b30 V:[UILabel:0x19115fd0'text']-(0)-|   (Names: '|':UITableViewCellContentView:0x19115f00 )>",
"<NSLayoutConstraint:0x191172c0 V:[UILabel:0x19115fd0'text'(>=65)]>",
"<NSLayoutConstraint:0x19087f30 'UIView-Encapsulated-Layout-Height' V:[UITableViewCellContentView:0x19115f00(45)]>"
它似乎使用45来计算UIView-Encapsulated-Layout-Height约束,即使没有为常规规则安装45高度.实际上,它打破了65高度约束并使用45,使行变短.当我从屏幕上滚动行并返回时,它们的高度被正确计算.
请注意,我在ViewDidLoad中使用以下内容:
self.tableView.rowHeight = UITableViewAutomaticDimension
self.tableView.estimatedRowHeight = 60.0;
我已经尝试将65高度的优先级从1000设置为750.它不再发出警告,但行为是相同的,因为它使用45高度.
我甚至尝试在ViewDidAppear中使用"[self.tableView reloadData]",但在正确调整大小之前它显示错误的高度.
有任何想法吗?
ios ×9
autolayout ×6
uitableview ×6
objective-c ×3
cocoa-touch ×2
swift ×2
constraints ×1
ios8 ×1
nsautolayout ×1
webview ×1