Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#Custom duration for showIn and dismissOut #71

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions KLCPopup/KLCPopup.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,12 @@ extern const KLCPopupLayout KLCPopupLayoutCenter;
// Overrides alpha value for dimmed background mask. default = 0.5
@property (nonatomic, assign) CGFloat dimmedMaskAlpha;

// Overrides animation duration for show in.
@property (nonatomic, assign) CGFloat showInDuration;

// Overrides duration for dismiss.
@property (nonatomic, assign) CGFloat dismissOutDuration;

// If YES, then popup will get dismissed when background is touched. default = YES.
@property (nonatomic, assign) BOOL shouldDismissOnBackgroundTouch;

Expand Down
44 changes: 22 additions & 22 deletions KLCPopup/KLCPopup.m
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ - (void)dismiss:(BOOL)animated {

if (animated && (_showType != KLCPopupShowTypeNone)) {
// Make fade happen faster than motion. Use linear for fades.
[UIView animateWithDuration:0.15
[UIView animateWithDuration:self.dismissOutDuration ?: 0.15
delay:0
options:UIViewAnimationOptionCurveLinear
animations:backgroundAnimationBlock
Expand All @@ -289,14 +289,14 @@ - (void)dismiss:(BOOL)animated {
}
};

NSTimeInterval bounce1Duration = 0.13;
NSTimeInterval bounce1Duration = self.dismissOutDuration ?: 0.13;
NSTimeInterval bounce2Duration = (bounce1Duration * 2.0);

// Animate content if needed
if (animated) {
switch (_dismissType) {
case KLCPopupDismissTypeFadeOut: {
[UIView animateWithDuration:0.15
[UIView animateWithDuration:self.dismissOutDuration ?: 0.15
delay:0
options:UIViewAnimationOptionCurveLinear
animations:^{
Expand All @@ -306,7 +306,7 @@ - (void)dismiss:(BOOL)animated {
}

case KLCPopupDismissTypeGrowOut: {
[UIView animateWithDuration:0.15
[UIView animateWithDuration:self.dismissOutDuration ?: 0.15
delay:0
options:kAnimationOptionCurveIOS7
animations:^{
Expand All @@ -317,7 +317,7 @@ - (void)dismiss:(BOOL)animated {
}

case KLCPopupDismissTypeShrinkOut: {
[UIView animateWithDuration:0.15
[UIView animateWithDuration:self.dismissOutDuration ?: 0.15
delay:0
options:kAnimationOptionCurveIOS7
animations:^{
Expand All @@ -328,7 +328,7 @@ - (void)dismiss:(BOOL)animated {
}

case KLCPopupDismissTypeSlideOutToTop: {
[UIView animateWithDuration:0.30
[UIView animateWithDuration:self.dismissOutDuration ?: 0.30
delay:0
options:kAnimationOptionCurveIOS7
animations:^{
Expand All @@ -341,7 +341,7 @@ - (void)dismiss:(BOOL)animated {
}

case KLCPopupDismissTypeSlideOutToBottom: {
[UIView animateWithDuration:0.30
[UIView animateWithDuration:self.dismissOutDuration ?: 0.30
delay:0
options:kAnimationOptionCurveIOS7
animations:^{
Expand All @@ -354,7 +354,7 @@ - (void)dismiss:(BOOL)animated {
}

case KLCPopupDismissTypeSlideOutToLeft: {
[UIView animateWithDuration:0.30
[UIView animateWithDuration:self.dismissOutDuration ?: 0.30
delay:0
options:kAnimationOptionCurveIOS7
animations:^{
Expand All @@ -367,7 +367,7 @@ - (void)dismiss:(BOOL)animated {
}

case KLCPopupDismissTypeSlideOutToRight: {
[UIView animateWithDuration:0.30
[UIView animateWithDuration:self.dismissOutDuration ?: 0.30
delay:0
options:kAnimationOptionCurveIOS7
animations:^{
Expand Down Expand Up @@ -565,7 +565,7 @@ - (void)showWithParameters:(NSDictionary*)parameters {

if (_showType != KLCPopupShowTypeNone) {
// Make fade happen faster than motion. Use linear for fades.
[UIView animateWithDuration:0.15
[UIView animateWithDuration:self.showInDuration ?: 0.15
delay:0
options:UIViewAnimationOptionCurveLinear
animations:backgroundAnimationBlock
Expand Down Expand Up @@ -755,7 +755,7 @@ - (void)showWithParameters:(NSDictionary*)parameters {
CGRect startFrame = finalContainerFrame;
_containerView.frame = startFrame;

[UIView animateWithDuration:0.15
[UIView animateWithDuration:self.showInDuration ?: 0.15
delay:0
options:UIViewAnimationOptionCurveLinear
animations:^{
Expand All @@ -773,7 +773,7 @@ - (void)showWithParameters:(NSDictionary*)parameters {
_containerView.frame = startFrame;
_containerView.transform = CGAffineTransformMakeScale(0.85, 0.85);

[UIView animateWithDuration:0.15
[UIView animateWithDuration:self.showInDuration ?: 0.15
delay:0
options:kAnimationOptionCurveIOS7 // note: this curve ignores durations
animations:^{
Expand All @@ -794,7 +794,7 @@ - (void)showWithParameters:(NSDictionary*)parameters {
_containerView.frame = startFrame;
_containerView.transform = CGAffineTransformMakeScale(1.25, 1.25);

[UIView animateWithDuration:0.15
[UIView animateWithDuration:self.showInDuration ?: 0.15
delay:0
options:kAnimationOptionCurveIOS7 // note: this curve ignores durations
animations:^{
Expand All @@ -814,7 +814,7 @@ - (void)showWithParameters:(NSDictionary*)parameters {
startFrame.origin.y = -CGRectGetHeight(finalContainerFrame);
_containerView.frame = startFrame;

[UIView animateWithDuration:0.30
[UIView animateWithDuration:self.showInDuration ?: 0.30
delay:0
options:kAnimationOptionCurveIOS7 // note: this curve ignores durations
animations:^{
Expand All @@ -831,7 +831,7 @@ - (void)showWithParameters:(NSDictionary*)parameters {
startFrame.origin.y = CGRectGetHeight(self.bounds);
_containerView.frame = startFrame;

[UIView animateWithDuration:0.30
[UIView animateWithDuration:self.showInDuration ?: 0.30
delay:0
options:kAnimationOptionCurveIOS7 // note: this curve ignores durations
animations:^{
Expand All @@ -848,7 +848,7 @@ - (void)showWithParameters:(NSDictionary*)parameters {
startFrame.origin.x = -CGRectGetWidth(finalContainerFrame);
_containerView.frame = startFrame;

[UIView animateWithDuration:0.30
[UIView animateWithDuration:self.showInDuration ?: 0.30
delay:0
options:kAnimationOptionCurveIOS7 // note: this curve ignores durations
animations:^{
Expand All @@ -865,7 +865,7 @@ - (void)showWithParameters:(NSDictionary*)parameters {
startFrame.origin.x = CGRectGetWidth(self.bounds);
_containerView.frame = startFrame;

[UIView animateWithDuration:0.30
[UIView animateWithDuration:self.showInDuration ?: 0.30
delay:0
options:kAnimationOptionCurveIOS7 // note: this curve ignores durations
animations:^{
Expand All @@ -883,7 +883,7 @@ - (void)showWithParameters:(NSDictionary*)parameters {
_containerView.frame = startFrame;
_containerView.transform = CGAffineTransformMakeScale(0.1, 0.1);

[UIView animateWithDuration:0.6
[UIView animateWithDuration:self.showInDuration ?: 0.60
delay:0.0
usingSpringWithDamping:0.8
initialSpringVelocity:15.0
Expand All @@ -904,7 +904,7 @@ - (void)showWithParameters:(NSDictionary*)parameters {
startFrame.origin.y = -CGRectGetHeight(finalContainerFrame);
_containerView.frame = startFrame;

[UIView animateWithDuration:0.6
[UIView animateWithDuration:self.showInDuration ?: 0.60
delay:0.0
usingSpringWithDamping:0.8
initialSpringVelocity:10.0
Expand All @@ -923,7 +923,7 @@ - (void)showWithParameters:(NSDictionary*)parameters {
startFrame.origin.y = CGRectGetHeight(self.bounds);
_containerView.frame = startFrame;

[UIView animateWithDuration:0.6
[UIView animateWithDuration:self.showInDuration ?: 0.60
delay:0.0
usingSpringWithDamping:0.8
initialSpringVelocity:10.0
Expand All @@ -942,7 +942,7 @@ - (void)showWithParameters:(NSDictionary*)parameters {
startFrame.origin.x = -CGRectGetWidth(finalContainerFrame);
_containerView.frame = startFrame;

[UIView animateWithDuration:0.6
[UIView animateWithDuration:self.showInDuration ?: 0.60
delay:0.0
usingSpringWithDamping:0.8
initialSpringVelocity:10.0
Expand All @@ -961,7 +961,7 @@ - (void)showWithParameters:(NSDictionary*)parameters {
startFrame.origin.x = CGRectGetWidth(self.bounds);
_containerView.frame = startFrame;

[UIView animateWithDuration:0.6
[UIView animateWithDuration:self.showInDuration ?: 0.60
delay:0.0
usingSpringWithDamping:0.8
initialSpringVelocity:10.0
Expand Down
5 changes: 5 additions & 0 deletions KLCPopupExample/KLCPopupExample.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,9 @@
LastUpgradeCheck = 0510;
ORGANIZATIONNAME = Kullect;
TargetAttributes = {
1FA76AAD195893080075A8E4 = {
DevelopmentTeam = 26SQZQ89WS;
};
1FA76AD1195893080075A8E4 = {
TestTargetID = 1FA76AAD195893080075A8E4;
};
Expand Down Expand Up @@ -386,6 +389,7 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage;
DEVELOPMENT_TEAM = 26SQZQ89WS;
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "KLCPopupExample/KLCPopupExample-Prefix.pch";
INFOPLIST_FILE = "KLCPopupExample/KLCPopupExample-Info.plist";
Expand All @@ -400,6 +404,7 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage;
DEVELOPMENT_TEAM = 26SQZQ89WS;
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "KLCPopupExample/KLCPopupExample-Prefix.pch";
INFOPLIST_FILE = "KLCPopupExample/KLCPopupExample-Info.plist";
Expand Down
4 changes: 4 additions & 0 deletions KLCPopupExample/KLCPopupExample/ViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,10 @@ - (void)showButtonPressed:(id)sender {
dismissOnBackgroundTouch:_shouldDismissOnBackgroundTouch
dismissOnContentTouch:_shouldDismissOnContentTouch];

// Custom duration for showIn and dismissOut
popup.showInDuration = 0.3;
popup.dismissOutDuration = 0.1;

if (_shouldDismissAfterDelay) {
[popup showWithLayout:layout duration:2.0];
} else {
Expand Down