From 7e6b9fba42b2aaa926043f2c9469c0f38253c934 Mon Sep 17 00:00:00 2001 From: Scott90 Date: Sun, 1 Dec 2013 21:05:42 -0600 Subject: [PATCH] Show previous alert (if available) upon dismissing of current --- SDCAlertView/SDCAlertViewController.m | 16 ++++++++++++++++ SDCAlertView/SDCViewController.m | 17 +++++++++++++++-- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/SDCAlertView/SDCAlertViewController.m b/SDCAlertView/SDCAlertViewController.m index ceea957c..bab913b5 100644 --- a/SDCAlertView/SDCAlertViewController.m +++ b/SDCAlertView/SDCAlertViewController.m @@ -124,6 +124,15 @@ - (void)showAlert:(SDCAlertView *)alert animated:(BOOL)animated { [self changeActiveWindowIfNeeded]; + if ([self.alertViews count] > 1) { + SDCAlertView *previousAlert = self.alertViews[0]; + CATransform3D transformFrom = CATransform3DMakeScale(1, 1, 1); + CATransform3D transformTo = CATransform3DMakeScale(SDCAlertViewDismissingAnimationScale, SDCAlertViewDismissingAnimationScale, 1); + + [self animateAlertTransform:previousAlert from:transformFrom to:transformTo]; + [self animateAlertOpacity:previousAlert from:1 to:0]; + } + [alert willBePresented]; if (animated) { @@ -169,6 +178,13 @@ - (void)dismissAlert:(SDCAlertView *)alert animated:(BOOL)animated completion:(v if ([self.alertViews count] == 0) { self.backgroundColorView.layer.opacity = 0; [self.backgroundColorView.layer addAnimation:opacityAnimation forKey:@"opacity"]; + } else { + [[self currentAlert] setNeedsUpdateConstraints]; + CATransform3D transformFrom = CATransform3DMakeScale(SDCAlertViewDismissingAnimationScale, SDCAlertViewDismissingAnimationScale, 1); + CATransform3D transformTo = CATransform3DMakeScale(1, 1, 1); + [self animateAlertTransform:[self currentAlert] from:transformFrom to:transformTo]; + + [self animateAlertOpacity:[self currentAlert] from:0 to:1]; } } completionHandler:dismissBlock]; } else { diff --git a/SDCAlertView/SDCViewController.m b/SDCAlertView/SDCViewController.m index 9e07a18e..6d4e8df2 100644 --- a/SDCAlertView/SDCViewController.m +++ b/SDCAlertView/SDCViewController.m @@ -13,7 +13,7 @@ #import "SDCAlertView.h" #import "UIView+SDCAutoLayout.h" -@interface SDCViewController () +@interface SDCViewController () @end @@ -23,9 +23,15 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath if (indexPath.section == 0) { [[[UIAlertView alloc] initWithTitle:@"Title" message:@"This is a message" - delegate:nil + delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"OK", nil] show]; + [[[UIAlertView alloc] initWithTitle:@"Title" + message:@"This is a message" + delegate:self + cancelButtonTitle:@"Cancel" + otherButtonTitles:@"OK", nil] show]; + } else if (indexPath.section == 1) { if (indexPath.row == 0) { [[[SDCAlertView alloc] initWithTitle:@"Title" @@ -33,6 +39,8 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath delegate:nil cancelButtonTitle:@"Cancel" otherButtonTitles:@"OK", nil] show]; + SDCAlertView *alert2 = [[SDCAlertView alloc] initWithTitle:@"Title" message:nil delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:nil, nil]; + [alert2 performSelector:@selector(show) withObject:nil afterDelay:3]; } else if (indexPath.row == 1) { [[[SDCAlertView alloc] initWithTitle:@"Title" message:@"This is a message" @@ -132,6 +140,11 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath [tableView deselectRowAtIndexPath:indexPath animated:YES]; } +- (void)didPresentAlertView:(UIAlertView *)alertView { + +} + + - (void)updateProgressView:(NSTimer *)timer { UIProgressView *progressView = [timer userInfo];