|
@@ -36,6 +36,8 @@
|
|
|
@property (nonatomic,copy) RAConstraint *(^ra_p_size_greaterThanOrEqualTo)(CGFloat size);
|
|
@property (nonatomic,copy) RAConstraint *(^ra_p_size_greaterThanOrEqualTo)(CGFloat size);
|
|
|
@property (nonatomic,copy) RAConstraint *(^ra_p_size_lessThanOrEqualTo)(CGFloat size);
|
|
@property (nonatomic,copy) RAConstraint *(^ra_p_size_lessThanOrEqualTo)(CGFloat size);
|
|
|
|
|
|
|
|
|
|
+@property (nonatomic,copy) void (^jk_p_modify)(CGFloat constant);
|
|
|
|
|
+
|
|
|
@end
|
|
@end
|
|
|
|
|
|
|
|
@implementation RAConstraint
|
|
@implementation RAConstraint
|
|
@@ -142,6 +144,19 @@
|
|
|
|
|
|
|
|
return weakSelf;
|
|
return weakSelf;
|
|
|
} copy];
|
|
} copy];
|
|
|
|
|
+
|
|
|
|
|
+ self.jk_p_modify = [^(CGFloat constant) {
|
|
|
|
|
+
|
|
|
|
|
+ weakSelf.constant = constant;
|
|
|
|
|
+ if (weakSelf.constraint) {
|
|
|
|
|
+ weakSelf.constraint.constant = constant;
|
|
|
|
|
+ if ([weakSelf appliedViewIsView]) {
|
|
|
|
|
+ UIView *appliedView = ((UIView *)weakSelf.appliedView);
|
|
|
|
|
+ [appliedView.superview layoutIfNeeded];
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ } copy];
|
|
|
}
|
|
}
|
|
|
return self;
|
|
return self;
|
|
|
}
|
|
}
|
|
@@ -178,7 +193,11 @@
|
|
|
return self.ra_p_size_greaterThanOrEqualTo;
|
|
return self.ra_p_size_greaterThanOrEqualTo;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-- (void)jk_uninstall {
|
|
|
|
|
|
|
+- (void (^)(CGFloat))jk_modify {
|
|
|
|
|
+ return self.jk_p_modify;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+- (void)ra_uninstall {
|
|
|
|
|
|
|
|
if (self.appliedView && self.appliedViewIsView && self.validate && self.constraint) {
|
|
if (self.appliedView && self.appliedViewIsView && self.validate && self.constraint) {
|
|
|
|
|
|
|
@@ -194,11 +213,12 @@
|
|
|
|
|
|
|
|
[self.appendConstraints enumerateKeysAndObjectsUsingBlock:^(NSString * _Nonnull key, RAConstraint * _Nonnull obj, BOOL * _Nonnull stop) {
|
|
[self.appendConstraints enumerateKeysAndObjectsUsingBlock:^(NSString * _Nonnull key, RAConstraint * _Nonnull obj, BOOL * _Nonnull stop) {
|
|
|
|
|
|
|
|
- [obj jk_uninstall];
|
|
|
|
|
|
|
+ [obj ra_uninstall];
|
|
|
}];
|
|
}];
|
|
|
|
|
|
|
|
self.validate = NO;
|
|
self.validate = NO;
|
|
|
self.constraint = nil;
|
|
self.constraint = nil;
|
|
|
|
|
+ self.identifier = nil;
|
|
|
|
|
|
|
|
self.toView = nil;
|
|
self.toView = nil;
|
|
|
self.relation = NSLayoutRelationEqual;
|
|
self.relation = NSLayoutRelationEqual;
|
|
@@ -209,7 +229,7 @@
|
|
|
[self.appendConstraints removeAllObjects];
|
|
[self.appendConstraints removeAllObjects];
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-- (void)jk_install {
|
|
|
|
|
|
|
+- (void)ra_install {
|
|
|
|
|
|
|
|
if (self.appliedView && self.appliedViewIsView && self.validate && !self.constraint) {
|
|
if (self.appliedView && self.appliedViewIsView && self.validate && !self.constraint) {
|
|
|
|
|
|
|
@@ -223,6 +243,7 @@
|
|
|
constant:self.constant];
|
|
constant:self.constant];
|
|
|
self.constraint = constraint;
|
|
self.constraint = constraint;
|
|
|
self.constraint.priority = self.priority;
|
|
self.constraint.priority = self.priority;
|
|
|
|
|
+ self.constraint.identifier = self.identifier;
|
|
|
|
|
|
|
|
if ((self.attribute == NSLayoutAttributeWidth || self.attribute == NSLayoutAttributeHeight) && !self.toView) {
|
|
if ((self.attribute == NSLayoutAttributeWidth || self.attribute == NSLayoutAttributeHeight) && !self.toView) {
|
|
|
[appliedView addConstraint:self.constraint];
|
|
[appliedView addConstraint:self.constraint];
|
|
@@ -233,7 +254,7 @@
|
|
|
|
|
|
|
|
[self.appendConstraints enumerateKeysAndObjectsUsingBlock:^(NSString * _Nonnull key, RAConstraint * _Nonnull obj, BOOL * _Nonnull stop) {
|
|
[self.appendConstraints enumerateKeysAndObjectsUsingBlock:^(NSString * _Nonnull key, RAConstraint * _Nonnull obj, BOOL * _Nonnull stop) {
|
|
|
|
|
|
|
|
- [obj jk_install];
|
|
|
|
|
|
|
+ [obj ra_install];
|
|
|
}];
|
|
}];
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -274,6 +295,8 @@
|
|
|
|
|
|
|
|
@property (nonatomic,strong) NSMutableArray<RAConstraint *> *constraints;
|
|
@property (nonatomic,strong) NSMutableArray<RAConstraint *> *constraints;
|
|
|
|
|
|
|
|
|
|
+@property (nonatomic,copy) void (^jk_modifyConstraint)(NSString *identifier, CGFloat constant);
|
|
|
|
|
+
|
|
|
@end
|
|
@end
|
|
|
|
|
|
|
|
@implementation RAConstraintMaker
|
|
@implementation RAConstraintMaker
|
|
@@ -292,10 +315,52 @@
|
|
|
self.width,
|
|
self.width,
|
|
|
self.height
|
|
self.height
|
|
|
]];
|
|
]];
|
|
|
|
|
+
|
|
|
|
|
+ __weak typeof(self) weakSelf = self;
|
|
|
|
|
+ self.jk_modifyConstraint = [^(NSString *identifier, CGFloat constant) {
|
|
|
|
|
+
|
|
|
|
|
+ NSDictionary *constraintRes = [weakSelf findConstraintOfView:weakSelf.appliedView byIdentifier:identifier];
|
|
|
|
|
+ if (constraintRes) {
|
|
|
|
|
+
|
|
|
|
|
+ UIView *view = constraintRes[@"view"];
|
|
|
|
|
+ NSLayoutConstraint *constraint = constraintRes[@"constraint"];
|
|
|
|
|
+
|
|
|
|
|
+ constraint.constant = constant;
|
|
|
|
|
+ [view layoutIfNeeded];
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ } copy];
|
|
|
}
|
|
}
|
|
|
return self;
|
|
return self;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+- (NSDictionary *)findConstraintOfView:(UIView *)view byIdentifier:(NSString *)identifier {
|
|
|
|
|
+ if (!view || !identifier) {
|
|
|
|
|
+ return nil;
|
|
|
|
|
+ }
|
|
|
|
|
+ NSLayoutConstraint *result = nil;
|
|
|
|
|
+
|
|
|
|
|
+ NSArray<NSLayoutConstraint *> *constraintArray = view.constraints;
|
|
|
|
|
+ for (NSLayoutConstraint *constraint in constraintArray) {
|
|
|
|
|
+ if (constraint.identifier && [constraint.identifier isEqualToString:identifier]) {
|
|
|
|
|
+ result = constraint;
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ if (result) {
|
|
|
|
|
+ return @{
|
|
|
|
|
+ @"view" : view,
|
|
|
|
|
+ @"constraint" : result
|
|
|
|
|
+ };
|
|
|
|
|
+ } else {
|
|
|
|
|
+ if (view.superview) {
|
|
|
|
|
+ return [self findConstraintOfView:view.superview byIdentifier:identifier];
|
|
|
|
|
+ } else {
|
|
|
|
|
+ return nil;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
- (NSMutableArray<RAConstraint *> *)constraints {
|
|
- (NSMutableArray<RAConstraint *> *)constraints {
|
|
|
if (!_constraints) {
|
|
if (!_constraints) {
|
|
|
_constraints = [NSMutableArray array];
|
|
_constraints = [NSMutableArray array];
|
|
@@ -422,21 +487,21 @@
|
|
|
return _ra_safeAreaBottom;
|
|
return _ra_safeAreaBottom;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-- (void)jk_install {
|
|
|
|
|
|
|
+- (void)ra_install {
|
|
|
if (self.appliedView) {
|
|
if (self.appliedView) {
|
|
|
|
|
|
|
|
for (RAConstraint *constraint in self.constraints) {
|
|
for (RAConstraint *constraint in self.constraints) {
|
|
|
- [constraint jk_install];
|
|
|
|
|
|
|
+ [constraint ra_install];
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-- (void)jk_uninstall {
|
|
|
|
|
|
|
+- (void)ra_uninstall {
|
|
|
|
|
|
|
|
if (self.appliedView) {
|
|
if (self.appliedView) {
|
|
|
|
|
|
|
|
for (RAConstraint *constraint in self.constraints) {
|
|
for (RAConstraint *constraint in self.constraints) {
|
|
|
- [constraint jk_uninstall];
|
|
|
|
|
|
|
+ [constraint ra_uninstall];
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -483,7 +548,7 @@ static const char RAMaker = '\a';
|
|
|
|
|
|
|
|
if (maker) {
|
|
if (maker) {
|
|
|
[self setRA_Maker:maker];
|
|
[self setRA_Maker:maker];
|
|
|
- [maker jk_install];
|
|
|
|
|
|
|
+ [maker ra_install];
|
|
|
|
|
|
|
|
[self.superview layoutIfNeeded];
|
|
[self.superview layoutIfNeeded];
|
|
|
}
|
|
}
|
|
@@ -491,7 +556,7 @@ static const char RAMaker = '\a';
|
|
|
|
|
|
|
|
- (void)ra_remakeConstraints:(void(^)(RAConstraintMaker *maker))remake {
|
|
- (void)ra_remakeConstraints:(void(^)(RAConstraintMaker *maker))remake {
|
|
|
|
|
|
|
|
- [[self ra_maker] jk_uninstall];
|
|
|
|
|
|
|
+ [[self ra_maker] ra_uninstall];
|
|
|
|
|
|
|
|
[self ra_applyConstraints:remake];
|
|
[self ra_applyConstraints:remake];
|
|
|
}
|
|
}
|
|
@@ -552,6 +617,12 @@ static const char RAMaker = '\a';
|
|
|
return [self ra_maker].ra_safeAreaBottom;
|
|
return [self ra_maker].ra_safeAreaBottom;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+// modify
|
|
|
|
|
+
|
|
|
|
|
+- (void (^)(NSString *, CGFloat))jk_modifyConstraint {
|
|
|
|
|
+ return [self ra_maker].jk_modifyConstraint;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
@end
|
|
@end
|
|
|
|
|
|
|
|
#pragma mark - View Controller
|
|
#pragma mark - View Controller
|