簡體   English   中英

解決僅iPhone Plus的突破約束

[英]Fixing breaking constraint iPhone Plus only

我有tableViewCell,並且有UIButton。 我設置了這樣的約束:

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)

它確實顯示了具有正確高度的按鈕,並且設置了正確的頂部和底部偏移量,但是在控制台中打印了錯誤日志:

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>

我以某種方式“不喜歡”我用恆定的值設置UIButton的高度,並設置頂部和底部的偏移量。 如何解決?

PS。 我的控制器是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)
    }

viewDidLoad調用setupTable

在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
        }

我沒有覆蓋heightForRowAtIndexPath。

問題在於您已經在明確設置像元(行)的高度。 您不能明確規定行高,也不能提供一整套完整的優先級垂直約束。 做一個或另一個。 要么顯式調整行的大小並提供不完整的約束,要么提供完整的約束並告訴該行自動調整自身的大小。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM