以编程方式禁用自动布局约束 [英] Programmatically disable auto-layout constraint
本文介绍了以编程方式禁用自动布局约束的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否有任何编程方法可以暂时禁用自动布局约束?在我再次需要之前,我根本不希望在一段时间内考虑该约束.
Is there any programatic way to temporarily disable an auto-layout constraint? I do not want that constraint to be considered for a certain period of time at all until I need it again.
推荐答案
在为 iOS 8.0 或更高版本开发时,只需在创建 IBOutlet 后使用 NSLayoutConstraint
的 isActive
属性即可.
When developing for iOS 8.0 or later, just use isActive
property of NSLayoutConstraint
after creating your IBOutlet.
更新
- 根据以下建议对插座有很强的参考,谢谢@rob mayoff.
- 按照以下建议在 Swift 4 中使用 .isActive 而不是 .active,谢谢@Mohit Singh.
您的单元格将具有以下出口:
your cell would have the following outlet:
@IBOutlet var photoBottomConstraint: NSLayoutConstraint!
并且您将访问 willDisplayCell
中的约束,例如:
and you would access the constraint in willDisplayCell
like:
myCell.photoBottomConstraint.isActive = false
当你再次需要它时:
myCell.photoBottomConstraint.isActive = true
这篇关于以编程方式禁用自动布局约束的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文