Authored by Jonas Budelmann

removing tap gesture from animation example

... ... @@ -152,7 +152,7 @@
#pragma mark - layout relation
- (id<MASConstraint> (^)(id))equalityWithBlock:(id<MASConstraint> (^)(id<MASConstraint> constraint, id attr))block {
- (id<MASConstraint> (^)(id))relationWithBlock:(id<MASConstraint> (^)(id<MASConstraint> constraint, id attr))block {
return ^id(id attr) {
if (!self.added) {
[self.delegate addConstraint:self];
... ... @@ -170,19 +170,19 @@
}
- (id<MASConstraint> (^)(id))equalTo {
return [self equalityWithBlock:^id(id<MASConstraint> constraint, id attr) {
return [self relationWithBlock:^id(id<MASConstraint> constraint, id attr) {
return constraint.equalTo(attr);
}];
}
- (id<MASConstraint> (^)(id))greaterThanOrEqualTo {
return [self equalityWithBlock:^id<MASConstraint>(id<MASConstraint> constraint, id attr) {
return [self relationWithBlock:^id<MASConstraint>(id<MASConstraint> constraint, id attr) {
return constraint.greaterThanOrEqualTo(attr);
}];
}
- (id<MASConstraint> (^)(id))lessThanOrEqualTo {
return [self equalityWithBlock:^id<MASConstraint>(id<MASConstraint> constraint, id attr) {
return [self relationWithBlock:^id<MASConstraint>(id<MASConstraint> constraint, id attr) {
return constraint.lessThanOrEqualTo(attr);
}];
}
... ...
... ... @@ -19,15 +19,22 @@ typedef float MASLayoutPriority;
@protocol MASConstraint <NSObject>
//layout constants
@property (nonatomic, copy, readonly) id<MASConstraint> (^insets)(UIEdgeInsets insets);
@property (nonatomic, copy, readonly) id<MASConstraint> (^sizeOffset)(CGSize offset);
@property (nonatomic, copy, readonly) id<MASConstraint> (^centerOffset)(CGPoint offset);
@property (nonatomic, copy, readonly) id<MASConstraint> (^offset)(CGFloat offset);
//layout multipliers
@property (nonatomic, copy, readonly) id<MASConstraint> (^percent)(CGFloat percent);
//layout priority
@property (nonatomic, copy, readonly) id<MASConstraint> (^priority)(UILayoutPriority priority);
@property (nonatomic, copy, readonly) id<MASConstraint> (^priorityLow)();
@property (nonatomic, copy, readonly) id<MASConstraint> (^priorityMedium)();
@property (nonatomic, copy, readonly) id<MASConstraint> (^priorityHigh)();
//layout relation
@property (nonatomic, copy, readonly) id<MASConstraint> (^equalTo)(id attr);
@property (nonatomic, copy, readonly) id<MASConstraint> (^greaterThanOrEqualTo)(id attr);
@property (nonatomic, copy, readonly) id<MASConstraint> (^lessThanOrEqualTo)(id attr);
... ...
... ... @@ -49,6 +49,21 @@
return self.layoutConstraint != nil;
}
- (void)setSecondViewAttribute:(id)secondViewAttribute {
if ([secondViewAttribute isKindOfClass:NSNumber.class]) {
self.layoutConstant = [secondViewAttribute doubleValue];
// } else if ([secondViewAttribute isKindOfClass:NSArray.class]) {
// //TODO Composite
} else if ([secondViewAttribute isKindOfClass:UIView.class]) {
_secondViewAttribute = [[MASViewAttribute alloc] initWithView:secondViewAttribute layoutAttribute:self.firstViewAttribute.layoutAttribute];
} else if ([secondViewAttribute isKindOfClass:MASViewAttribute.class]) {
_secondViewAttribute = secondViewAttribute;
} else {
NSAssert(YES, @"attempting to add unsupported attribute: %@", secondViewAttribute);
}
[self.delegate addConstraint:self];
}
- (instancetype)cloneIfNeeded {
if (self.hasLayoutRelation) {
MASViewAttribute *firstViewAttribute = [[MASViewAttribute alloc] initWithView:self.firstViewAttribute.view layoutAttribute:self.firstViewAttribute.layoutAttribute];
... ... @@ -174,21 +189,6 @@
#pragma mark - layout relation
- (void)setSecondViewAttribute:(id)secondViewAttribute {
if ([secondViewAttribute isKindOfClass:NSNumber.class]) {
self.layoutConstant = [secondViewAttribute doubleValue];
} else if ([secondViewAttribute isKindOfClass:NSArray.class]) {
//TODO Composite
} else if ([secondViewAttribute isKindOfClass:UIView.class]) {
_secondViewAttribute = [[MASViewAttribute alloc] initWithView:secondViewAttribute layoutAttribute:self.firstViewAttribute.layoutAttribute];
} else if ([secondViewAttribute isKindOfClass:MASViewAttribute.class]) {
_secondViewAttribute = secondViewAttribute;
} else {
NSAssert(YES, @"attempting to add unsupported attribute: %@", secondViewAttribute);
}
[self.delegate addConstraint:self];
}
- (id<MASConstraint> (^)(id))equalTo {
return ^id(id attr) {
NSAssert(!self.hasBeenCommitted,
... ...
... ... @@ -79,23 +79,35 @@
make.height.equalTo(view2.mas_height);
}];
UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(didTapWithGestureRecognizer:)];
[self addGestureRecognizer:tapGestureRecognizer];
return self;
}
- (void)didTapWithGestureRecognizer:(UITapGestureRecognizer *)tapGestureRecognizer {
self.padding += 20;
UIEdgeInsets paddingInsets = UIEdgeInsetsMake(self.padding, self.padding, self.padding, self.padding);
- (void)didMoveToSuperview {
[self startAnimatingWithInvertedInsets:NO];
}
- (void)willMoveToSuperview:(UIView *)newSuperview {
if (!newSuperview) {
[self.layer removeAllAnimations];
}
}
- (void)startAnimatingWithInvertedInsets:(BOOL)invertedInsets {
int padding = invertedInsets ? 100 : self.padding;
UIEdgeInsets paddingInsets = UIEdgeInsetsMake(padding, padding, padding, padding);
for (id<MASConstraint> constraint in self.animatableConstraints) {
constraint.insets(paddingInsets);
}
[UIView animateWithDuration:0.4 animations:^{
[UIView animateWithDuration:1 animations:^{
[self layoutIfNeeded];
} completion:^(BOOL finished) {
if (finished) {
[self startAnimatingWithInvertedInsets:!invertedInsets];
}
}];
}
@end
... ...
... ... @@ -83,6 +83,8 @@ it(@"should create width and height children", ^{
it(@"should complete children", ^{
UIView *view = UIView.new;
MASCompositeConstraint *composite = createCompositeWithType(MASCompositeViewConstraintTypeSize);
//first equality statement
composite.equalTo(view).sizeOffset(CGSizeMake(90, 30));
[verify(composite.delegate) addConstraint:(id)composite];
... ... @@ -100,6 +102,7 @@ it(@"should complete children", ^{
expect(viewConstraint.secondViewAttribute.layoutAttribute).to.equal(NSLayoutAttributeHeight);
expect(viewConstraint.layoutConstant).to.equal(30);
//chain another equality statement
composite.greaterThanOrEqualTo(@6);
expect(composite.completedChildConstraints).to.haveCountOf(4);
expect(composite.currentChildConstraints).to.haveCountOf(2);
... ... @@ -113,6 +116,15 @@ it(@"should complete children", ^{
expect(viewConstraint.secondViewAttribute.view).to.beNil();
expect(viewConstraint.secondViewAttribute.layoutAttribute).to.equal(0);
expect(viewConstraint.layoutConstant).to.equal(6);
//still referencing same view
viewConstraint = composite.currentChildConstraints[0];
expect(viewConstraint.firstViewAttribute.view).to.beIdenticalTo(composite.view);
expect(viewConstraint.firstViewAttribute.layoutAttribute).to.equal(NSLayoutAttributeWidth);
viewConstraint = composite.currentChildConstraints[1];
expect(viewConstraint.firstViewAttribute.view).to.beIdenticalTo(composite.view);
expect(viewConstraint.firstViewAttribute.layoutAttribute).to.equal(NSLayoutAttributeHeight);
});
SpecEnd
\ No newline at end of file
... ...