Selaa lähdekoodia

removing tap gesture from animation example

Jonas Budelmann 12 vuotta sitten
vanhempi
commit
55b2fb8c4c

+ 4 - 4
Masonry/MASCompositeConstraint.m

@@ -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);
     }];
 }

+ 7 - 0
Masonry/MASConstraint.h

@@ -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);

+ 15 - 15
Masonry/MASViewConstraint.m

@@ -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,

+ 19 - 7
MasonryExamples/MasonryExamples/MASExampleAnimatedView.m

@@ -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
 

+ 12 - 0
MasonryTests/MASCompositeConstraintSpec.m

@@ -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