修改容器视图的高度

这里是我的应用程序,左侧的配置文件(ProfileViewController)和右侧的容器视图(ContainerViewController)。我试图实现的是一旦containerViewController完成了它的工作,它将更新UIView的高度。修改容器视图的高度

// ContainerViewController.swift 

let heightConstraint = self.view.constraints.filter { $0.identifier == "Height" }.first

heightConstraint?.constant = height

当浏览限制的名单,他们都是emtpy,我也设立在故事板的一些限制。所以为什么 ?有什么方法可以访问ContainerViewController中的UIView?

PS:

DispatchQueue.main.async { 

self.view.frame = CGRect(x: 0, y: 0, width: width, height: height)

}

听起来工作,但我认为,修改约束是正确的?不 ?

回答:

我想要做的是为约束设置IBOutlet,并将其存储在ContainerView中。

即使未来代码(或故事板)发生更改,这种方式也不会依赖订单号或其他任何方式来获取此约束。

是的,正确的方法是设置约束常数,而不是改变框架。 但请注意,即使是约束条件的不断变化也需要放在主(UI)线程上 - (根据您的代码,我假设您正在处理线程)。

以上是 修改容器视图的高度 的全部内容, 来源链接: utcz.com/qa/265976.html

回到顶部