@@ -41,8 +41,8 @@ @interface ViewController ()
41
41
@property (weak , nonatomic ) IBOutlet UIView *blueView;
42
42
43
43
@property (weak , nonatomic ) IBOutlet NSLayoutConstraint *viewSpacingContraint;
44
- @property (strong , nonatomic ) NSLayoutConstraint *yellowViewConstraint ;
45
- @property (strong , nonatomic ) NSLayoutConstraint *blueViewConstraint ;
44
+ @property (weak , nonatomic ) IBOutlet NSLayoutConstraint *blueViewConstraint ;
45
+ @property (weak , nonatomic ) IBOutlet NSLayoutConstraint *yellowViewConstraint ;
46
46
47
47
@end
48
48
@@ -69,43 +69,15 @@ - (IBAction)enableMode:(UISwitch *)sender {
69
69
}];
70
70
}
71
71
72
- // "[yellowView]-|"
73
- - (NSLayoutConstraint *)yellowViewConstraint {
74
- if (!_yellowViewConstraint) {
75
- _yellowViewConstraint = [NSLayoutConstraint constraintWithItem: self .yellowView
76
- attribute: NSLayoutAttributeTrailing
77
- relatedBy: NSLayoutRelationEqual
78
- toItem: self .view
79
- attribute: NSLayoutAttributeTrailingMargin
80
- multiplier: 1.0
81
- constant: 0.0 ];
82
- }
83
- return _yellowViewConstraint;
84
- }
85
-
86
- // "[blueView]-|"
87
- - (NSLayoutConstraint *)blueViewConstraint {
88
- if (!_blueViewConstraint) {
89
- _blueViewConstraint = [NSLayoutConstraint constraintWithItem: self .blueView
90
- attribute: NSLayoutAttributeTrailing
91
- relatedBy: NSLayoutRelationEqual
92
- toItem: self .view
93
- attribute: NSLayoutAttributeTrailingMargin
94
- multiplier: 1.0
95
- constant: 0.0 ];
96
- }
97
- return _blueViewConstraint;
98
- }
99
-
100
72
- (void )updateConstraintsForMode {
101
73
if (self.modeSwitch .isOn ) {
102
74
self.viewSpacingContraint .constant = 8.0 ;
103
- [ self .view removeConstraint: self . yellowViewConstraint] ;
104
- [ self .view addConstraint: self . blueViewConstraint] ;
75
+ self.yellowViewConstraint . priority = 750 ;
76
+ self.blueViewConstraint . priority = 751 ;
105
77
} else {
106
- [self .view removeConstraint: self .blueViewConstraint];
107
- [self .view addConstraint: self .yellowViewConstraint];
108
78
self.viewSpacingContraint .constant = self.view .frame .size .width ;
79
+ self.blueViewConstraint .priority = 750 ;
80
+ self.yellowViewConstraint .priority = 751 ;
109
81
}
110
82
}
111
83
0 commit comments