Tweaked uninstalling constraints and removed unused code blocks

This commit is contained in:
Robert Payne 2015-04-11 18:32:33 +12:00
parent ebe9bb1e8d
commit 2dec123ce0
1 changed files with 11 additions and 10 deletions

View File

@ -405,7 +405,7 @@ final public class Constraint {
self.installInfo!.layoutConstraints.addObject(layoutConstraint) self.installInfo!.layoutConstraints.addObject(layoutConstraint)
} }
// store the layout constraints against the installed on view // store the layout constraints against the layout from view
layoutFrom!.snp_installedLayoutConstraints += newLayoutConstraints layoutFrom!.snp_installedLayoutConstraints += newLayoutConstraints
// return the new constraints // return the new constraints
@ -414,18 +414,22 @@ final public class Constraint {
internal func uninstallFromView() { internal func uninstallFromView() {
if let installInfo = self.installInfo, if let installInfo = self.installInfo,
let installedOnView = installInfo.view,
let installedLayoutConstraints = installInfo.layoutConstraints.allObjects as? [LayoutConstraint] { let installedLayoutConstraints = installInfo.layoutConstraints.allObjects as? [LayoutConstraint] {
if installedLayoutConstraints.count > 0 { if installedLayoutConstraints.count > 0 {
if let installedOnView = installInfo.view {
// remove the constraints from the UIView's storage // remove the constraints from the UIView's storage
installedOnView.removeConstraints(installedLayoutConstraints) installedOnView.removeConstraints(installedLayoutConstraints)
}
// remove the constraints from our associated object storage // remove the constraints from the from item view
installedOnView.snp_installedLayoutConstraints = installedOnView.snp_installedLayoutConstraints.filter { if let fromView = self.fromItem.view {
fromView.snp_installedLayoutConstraints = fromView.snp_installedLayoutConstraints.filter {
return !contains(installedLayoutConstraints, $0) return !contains(installedLayoutConstraints, $0)
} }
} }
}
} }
self.installInfo = nil self.installInfo = nil
@ -442,9 +446,6 @@ final public class Constraint {
private var offset: Any = Float(0.0) private var offset: Any = Float(0.0)
private var installInfo: ConstraintInstallInfo? private var installInfo: ConstraintInstallInfo?
private var installed: Bool {
return (self.installInfo != nil)
}
private func addConstraint(attributes: ConstraintAttributes) -> Constraint { private func addConstraint(attributes: ConstraintAttributes) -> Constraint {
if self.relation == nil { if self.relation == nil {