小编kvo*_*the的帖子

systemLayoutSizeFittingSize在第一次调用时给出不正确的大小

我正在尝试根据约束计算表视图头的高度.当我使用该layoutMarginsGuide属性时,我得到了错误的大小调用systemLayoutSizeFittingSize.如果我在不使用边距指南的情况下固定边缘,则可以正常工作.

这是代码:

class SomeVC: UIViewController, UITableViewDataSource, UITableViewDelegate {

// MARK: Properties

let tableView = UITableView()
let headerView = UIView()
let circle = UIView()
let circleSize: CGFloat = 100



// MARK: Methods

override func viewDidLoad() {
    super.viewDidLoad()

    tableView.delegate = self
    tableView.dataSource = self
    tableView.registerClass(UITableViewCell.self, forCellReuseIdentifier: "cellID")
    view.addSubview(tableView)

    headerView.layoutMargins = UIEdgeInsetsMake(20, 20, 20, 20)
    headerView.backgroundColor = UIColor.grayColor().colorWithAlphaComponent(0.36)

    circle.backgroundColor = UIColor.grayColor()
    circle.layer.cornerRadius = circleSize/2
    headerView.addSubview(circle)


    // Constraints for circle

    let margins = headerView.layoutMarginsGuide

    circle.translatesAutoresizingMaskIntoConstraints = false
    circle.topAnchor.constraintEqualToAnchor(margins.topAnchor).active = true …
Run Code Online (Sandbox Code Playgroud)

ios autolayout swift

6
推荐指数
1
解决办法
1309
查看次数

标签 统计

autolayout ×1

ios ×1

swift ×1