Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
940b0db
commit 8734da5
Showing
9 changed files
with
300 additions
and
195 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// | ||
// AMPopTip+Animation.h | ||
// AMPopTip | ||
// | ||
// Created by Andrea Mazzini on 10/06/15. | ||
// Copyright (c) 2015 Fancy Pixel. All rights reserved. | ||
// | ||
|
||
#import "AMPopTip.h" | ||
|
||
@interface AMPopTip (Animation) | ||
|
||
- (void)_startActionAnimation; | ||
- (void)_stopActionAnimation; | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
// | ||
// AMPopTip+Animation.m | ||
// AMPopTip | ||
// | ||
// Created by Andrea Mazzini on 10/06/15. | ||
// Copyright (c) 2015 Fancy Pixel. All rights reserved. | ||
// | ||
|
||
#import "AMPopTip+Animation.h" | ||
#import <objc/runtime.h> | ||
|
||
@implementation AMPopTip (Animation) | ||
|
||
- (void)setShouldBounce:(BOOL)shouldBounce { objc_setAssociatedObject(self, @selector(shouldBounce), [NSNumber numberWithBool:shouldBounce], OBJC_ASSOCIATION_RETAIN);} | ||
- (BOOL)shouldBounce { return [objc_getAssociatedObject(self, @selector(shouldBounce)) boolValue]; } | ||
|
||
- (void)_startActionAnimation { | ||
switch (self.actionAnimation) { | ||
case AMPopTipActionAnimationBounce: | ||
self.shouldBounce = YES; | ||
[self bounceAnimation]; | ||
break; | ||
case AMPopTipActionAnimationFloat: | ||
[self floatAnimation]; | ||
break; | ||
case AMPopTipActionAnimationPulse: | ||
[self pulseAnimation]; | ||
break; | ||
case AMPopTipActionAnimationNone: | ||
return; | ||
break; | ||
default: | ||
break; | ||
} | ||
} | ||
|
||
- (void)floatAnimation { | ||
CGFloat xOffset = 0; | ||
CGFloat yOffset = 0; | ||
switch (self.direction) { | ||
case AMPopTipDirectionUp: | ||
yOffset = -self.actionFloatOffset; | ||
break; | ||
case AMPopTipDirectionDown: | ||
yOffset = self.actionFloatOffset; | ||
break; | ||
case AMPopTipDirectionLeft: | ||
xOffset = -self.actionFloatOffset; | ||
break; | ||
case AMPopTipDirectionRight: | ||
xOffset = self.actionFloatOffset; | ||
break; | ||
case AMPopTipDirectionNone: | ||
yOffset = -self.actionFloatOffset; | ||
break; | ||
} | ||
|
||
[UIView animateWithDuration:(self.actionAnimationIn / 2) delay:self.actionDelayIn options:(UIViewAnimationOptionRepeat | UIViewAnimationOptionBeginFromCurrentState | UIViewAnimationOptionCurveEaseInOut | UIViewAnimationOptionAutoreverse | UIViewAnimationOptionAllowUserInteraction) animations:^{ | ||
self.transform = CGAffineTransformMakeTranslation(xOffset, yOffset); | ||
} completion:nil]; | ||
} | ||
|
||
- (void)bounceAnimation { | ||
CGFloat xOffset = 0; | ||
CGFloat yOffset = 0; | ||
switch (self.direction) { | ||
case AMPopTipDirectionUp: | ||
yOffset = -self.actionBounceOffset; | ||
break; | ||
case AMPopTipDirectionDown: | ||
yOffset = self.actionBounceOffset; | ||
break; | ||
case AMPopTipDirectionLeft: | ||
xOffset = -self.actionBounceOffset; | ||
break; | ||
case AMPopTipDirectionRight: | ||
xOffset = self.actionBounceOffset; | ||
break; | ||
case AMPopTipDirectionNone: | ||
yOffset = -self.actionBounceOffset; | ||
break; | ||
} | ||
|
||
[UIView animateWithDuration:(self.actionAnimationIn / 10) delay:self.actionDelayIn options:(UIViewAnimationOptionCurveEaseIn | UIViewAnimationOptionAllowUserInteraction) animations:^{ | ||
self.transform = CGAffineTransformMakeTranslation(xOffset, yOffset); | ||
} completion:^(BOOL finished) { | ||
[UIView animateWithDuration:(self.actionAnimationIn - self.actionAnimationIn / 10) delay:0 usingSpringWithDamping:0.4 initialSpringVelocity:1 options:0 animations:^{ | ||
self.transform = CGAffineTransformIdentity; | ||
} completion:^(BOOL done) { | ||
if (self.shouldBounce && done) { | ||
[self bounceAnimation]; | ||
} | ||
}]; | ||
}]; | ||
} | ||
|
||
- (void)pulseAnimation { | ||
[UIView animateWithDuration:(self.actionAnimationIn / 2) delay:self.actionDelayIn options:(UIViewAnimationOptionRepeat | UIViewAnimationOptionBeginFromCurrentState | UIViewAnimationOptionCurveEaseInOut | UIViewAnimationOptionAutoreverse | UIViewAnimationOptionAllowUserInteraction) animations:^{ | ||
self.transform = CGAffineTransformMakeScale(self.actionPulseOffset, self.actionPulseOffset); | ||
} completion:nil]; | ||
} | ||
|
||
- (void)_stopActionAnimation { | ||
self.shouldBounce = NO; | ||
[UIView animateWithDuration:(self.actionAnimationOut / 2) delay:self.actionDelayOut options:UIViewAnimationOptionBeginFromCurrentState animations:^{ | ||
self.transform = CGAffineTransformIdentity; | ||
} completion:^(BOOL finished) { | ||
[self.layer removeAllAnimations]; | ||
}]; | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// | ||
// AMPopTip+Entrance.h | ||
// AMPopTip | ||
// | ||
// Created by Andrea Mazzini on 10/06/15. | ||
// Copyright (c) 2015 Fancy Pixel. All rights reserved. | ||
// | ||
|
||
#import "AMPopTip.h" | ||
|
||
@interface AMPopTip (Entrance) | ||
|
||
- (void)performEntranceAnimation:(void (^)())completion; | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
// | ||
// AMPopTip+Entrance.m | ||
// AMPopTip | ||
// | ||
// Created by Andrea Mazzini on 10/06/15. | ||
// Copyright (c) 2015 Fancy Pixel. All rights reserved. | ||
// | ||
|
||
#import "AMPopTip+Entrance.h" | ||
|
||
@implementation AMPopTip (Entrance) | ||
|
||
- (void)performEntranceAnimation:(void (^)())completion { | ||
switch (self.entranceAnimation) { | ||
case AMPopTipEntranceAnimationScale: { | ||
[self entranceScale:completion]; | ||
break; | ||
} | ||
case AMPopTipEntranceAnimationTransition: { | ||
[self entranceTransition:completion]; | ||
break; | ||
} | ||
case AMPopTipEntranceAnimationCustom: { | ||
[self.containerView addSubview:self]; | ||
if (self.entranceAnimationHandler) { | ||
self.entranceAnimationHandler(^{ | ||
completion(); | ||
}); | ||
} | ||
} | ||
case AMPopTipEntranceAnimationNone: { | ||
[self.containerView addSubview:self]; | ||
completion(); | ||
break; | ||
} | ||
default: | ||
break; | ||
} | ||
} | ||
|
||
- (void)entranceTransition:(void (^)())completion { | ||
self.transform = CGAffineTransformMakeScale(0.6, 0.6); | ||
switch (self.direction) { | ||
case AMPopTipDirectionUp: | ||
self.transform = CGAffineTransformTranslate(self.transform, 0, -self.fromFrame.origin.y); | ||
break; | ||
case AMPopTipDirectionDown: | ||
self.transform = CGAffineTransformTranslate(self.transform, 0, (self.containerView.frame.size.height - self.fromFrame.origin.y)); | ||
break; | ||
case AMPopTipDirectionLeft: | ||
self.transform = CGAffineTransformTranslate(self.transform, -self.fromFrame.origin.x, 0); | ||
break; | ||
case AMPopTipDirectionRight: | ||
self.transform = CGAffineTransformTranslate(self.transform, (self.containerView.frame.size.width - self.fromFrame.origin.x), 0); | ||
break; | ||
case AMPopTipDirectionNone: | ||
self.transform = CGAffineTransformTranslate(self.transform, 0, (self.containerView.frame.size.height - self.fromFrame.origin.y)); | ||
break; | ||
|
||
default: | ||
break; | ||
} | ||
[self.containerView addSubview:self]; | ||
|
||
[UIView animateWithDuration:self.animationIn delay:self.delayIn usingSpringWithDamping:0.6 initialSpringVelocity:1.5 options:(UIViewAnimationOptionCurveEaseInOut) animations:^{ | ||
self.transform = CGAffineTransformIdentity; | ||
} completion:^(BOOL completed){ | ||
if (completed) { | ||
completion(); | ||
} | ||
}]; | ||
} | ||
|
||
- (void)entranceScale:(void (^)())completion { | ||
self.transform = CGAffineTransformMakeScale(0, 0); | ||
[self.containerView addSubview:self]; | ||
|
||
[UIView animateWithDuration:self.animationIn delay:self.delayIn usingSpringWithDamping:0.6 initialSpringVelocity:1.5 options:(UIViewAnimationOptionCurveEaseInOut) animations:^{ | ||
self.transform = CGAffineTransformIdentity; | ||
} completion:^(BOOL completed){ | ||
if (completed) { | ||
completion(); | ||
} | ||
}]; | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.