简体   繁体   English

解决仅iPhone Plus的突破约束

[英]Fixing breaking constraint iPhone Plus only

I have tableViewCell, and it have UIButton. 我有tableViewCell,并且有UIButton。 I set up constraints like that: 我设置了这样的约束:

make.left.equalTo(contentView.snp.left).offset(16)
                make.right.equalTo(contentView.snp.right).offset(-16)
                make.bottom.equalTo(contentView.snp.bottom).offset(-46)
                make.top.equalTo(contentView.snp.top).offset(24)
                make.height.equalTo(64)

It does show button with correct height and set top and bottom offsets correct, but it print error log in console: 它确实显示了具有正确高度的按钮,并且设置了正确的顶部和底部偏移量,但是在控制台中打印了错误日志:

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. 
(
    "<SnapKit.LayoutConstraint:0x6000002a34e0@RoundedButtonCell.swift#49 POS2.MSButton:0x7faf22c674b0.bottom == UITableViewCellContentView:0x7faf22c672c0.bottom - 46.0>",
    "<SnapKit.LayoutConstraint:0x6000000b8600@RoundedButtonCell.swift#50 POS2.MSButton:0x7faf22c674b0.top == UITableViewCellContentView:0x7faf22c672c0.top + 24.0>",
    "<SnapKit.LayoutConstraint:0x6000002a3de0@RoundedButtonCell.swift#51 POS2.MSButton:0x7faf22c674b0.height == 64.0>",
    "<NSLayoutConstraint:0x604000484420 'UIView-Encapsulated-Layout-Height' UITableViewCellContentView:0x7faf22c672c0.height == 134   (active)>"
)

Will attempt to recover by breaking constraint 
<SnapKit.LayoutConstraint:0x6000002a3de0@RoundedButtonCell.swift#51 POS2.MSButton:0x7faf22c674b0.height == 64.0>

I suppose it somehow "dont like" that i set UIButton height with constant, and set top and bottom offsets. 我以某种方式“不喜欢”我用恒定的值设置UIButton的高度,并设置顶部和底部的偏移量。 How to fix that? 如何解决?

PS. PS。 My controller is UITableViewController, i configure tableView like that: 我的控制器是UITableViewController,我这样配置tableView:

private func setupTable() {
        tableView.estimatedRowHeight = 40
        tableView.rowHeight = UITableViewAutomaticDimension

        tableView.separatorInset = .zero
        tableView.separatorColor = .clear

        tableView.keyboardDismissMode = .onDrag

        tableView.tableFooterView = nil
        tableView.tableHeaderView = nil

        tableView.delegate = self
        tableView.dataSource = self

        tableView.register(RadioButtonCell.self, forCellReuseIdentifier: MSTableViewCellType.radioButtonCell.rawValue)
        tableView.register(InputViewCell.self, forCellReuseIdentifier: MSTableViewCellType.inputViewCell.rawValue)
        tableView.register(CommentViewCell.self, forCellReuseIdentifier: MSTableViewCellType.commentViewCell.rawValue)
        tableView.register(RoundedButtonCell.self, forCellReuseIdentifier: MSTableViewCellType.roundedButtonViewCell.rawValue)
    }

setupTable is called in viewDidLoad viewDidLoad调用setupTable

In cellForRow: 在cellForRow中:

  case .roundedButton:
            let cell = tableView.dequeueReusableCell(withIdentifier: MSTableViewCellType.roundedButtonViewCell.rawValue, for: indexPath) as! RoundedButtonCell
            guard let model = fieldModel as? TextContainViewModel else { return UITableViewCell()}
            cell.setup(title: model.title)
            cell.contentView.layoutMargins = UIEdgeInsets(top: 24, left: 16, bottom: 46, right: 16)
            cell.layoutIfNeeded()

            return cell
        }

I did not override heightForRowAtIndexPath. 我没有覆盖heightForRowAtIndexPath。

The problem is that you are already setting the cell (row) height explicitly. 问题在于您已经在明确设置像元(行)的高度。 You cannot dictate the row height explicitly and also provide a complete set of full priority vertical constraints. 您不能明确规定行高,也不能提供一整套完整的优先级垂直约束。 Do one or the other. 做一个或另一个。 Either size the row explicitly and provide incomplete constraints, or provide complete constraints and tell the row to size itself automatically. 要么显式调整行的大小并提供不完整的约束,要么提供完整的约束并告诉该行自动调整自身的大小。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM