Showing
1 changed file
with
11 additions
and
6 deletions
@@ -12,6 +12,7 @@ | @@ -12,6 +12,7 @@ | ||
12 | 12 | ||
13 | @property (nonatomic, strong) NSMutableArray *animatableConstraints; | 13 | @property (nonatomic, strong) NSMutableArray *animatableConstraints; |
14 | @property (nonatomic, assign) int padding; | 14 | @property (nonatomic, assign) int padding; |
15 | +@property (nonatomic, assign) BOOL animating; | ||
15 | 16 | ||
16 | @end | 17 | @end |
17 | 18 | ||
@@ -80,16 +81,21 @@ | @@ -80,16 +81,21 @@ | ||
80 | 81 | ||
81 | - (void)didMoveToSuperview { | 82 | - (void)didMoveToSuperview { |
82 | [self layoutIfNeeded]; | 83 | [self layoutIfNeeded]; |
83 | - [self startAnimatingWithInvertedInsets:NO]; | 84 | + |
85 | + if (self.superview) { | ||
86 | + self.animating = YES; | ||
87 | + [self animateWithInvertedInsets:NO]; | ||
88 | + } | ||
84 | } | 89 | } |
85 | 90 | ||
86 | - (void)willMoveToSuperview:(UIView *)newSuperview { | 91 | - (void)willMoveToSuperview:(UIView *)newSuperview { |
87 | if (!newSuperview) { | 92 | if (!newSuperview) { |
88 | - [self.layer removeAllAnimations]; | 93 | + self.animating = NO; |
89 | } | 94 | } |
90 | } | 95 | } |
91 | 96 | ||
92 | -- (void)startAnimatingWithInvertedInsets:(BOOL)invertedInsets { | 97 | +- (void)animateWithInvertedInsets:(BOOL)invertedInsets { |
98 | + if (!self.animating) return; | ||
93 | int padding = invertedInsets ? 100 : self.padding; | 99 | int padding = invertedInsets ? 100 : self.padding; |
94 | UIEdgeInsets paddingInsets = UIEdgeInsetsMake(padding, padding, padding, padding); | 100 | UIEdgeInsets paddingInsets = UIEdgeInsetsMake(padding, padding, padding, padding); |
95 | for (id<MASConstraint> constraint in self.animatableConstraints) { | 101 | for (id<MASConstraint> constraint in self.animatableConstraints) { |
@@ -99,9 +105,8 @@ | @@ -99,9 +105,8 @@ | ||
99 | [UIView animateWithDuration:1 animations:^{ | 105 | [UIView animateWithDuration:1 animations:^{ |
100 | [self layoutIfNeeded]; | 106 | [self layoutIfNeeded]; |
101 | } completion:^(BOOL finished) { | 107 | } completion:^(BOOL finished) { |
102 | - if (finished) { | ||
103 | - [self startAnimatingWithInvertedInsets:!invertedInsets]; | ||
104 | - } | 108 | + //repeat! |
109 | + [self animateWithInvertedInsets:!invertedInsets]; | ||
105 | }]; | 110 | }]; |
106 | } | 111 | } |
107 | 112 |
-
Please register or login to post a comment