From 5de4c4e2ef61dfaf8b080e0b3b2bbf0f47a439f9 Mon Sep 17 00:00:00 2001 From: xiangyuh Date: Fri, 3 Oct 2014 16:38:28 +0800 Subject: [PATCH] AFPopUpView mets with self-definedanimations blocks with AFPopUpView hide animations . This patch supports AFPopUpView hide with actions (animations) blocks. --- AFPopupView.h | 2 +- AFPopupView.m | 7 +++++-- Demo/.DS_Store | Bin 6148 -> 6148 bytes Demo/AFPopup-Demo/AFPopupView.h | 4 +++- Demo/AFPopup-Demo/AFPopupView.m | 14 +++++++++++++- Demo/AFPopup-Demo/ViewController.m | 2 +- 6 files changed, 23 insertions(+), 6 deletions(-) diff --git a/AFPopupView.h b/AFPopupView.h index 0c67295..d243908 100644 --- a/AFPopupView.h +++ b/AFPopupView.h @@ -15,6 +15,6 @@ +(AFPopupView *)popupWithView:(UIView *)popupView; -(void)show; --(void)hide; +-(void)hideWithActions:(void (^)(void))actions; @end diff --git a/AFPopupView.m b/AFPopupView.m index 4e5cec2..99aeab6 100644 --- a/AFPopupView.m +++ b/AFPopupView.m @@ -131,7 +131,7 @@ -(void)show { } --(void)hide { +-(void)hideWithActions:(void (^)(void))actions { [UIView animateWithDuration:0.4 delay:0 @@ -160,13 +160,16 @@ -(void)hide { _renderImage.layer.transform = CATransform3DMakePerspective(0, 0); } completion:^(BOOL finished) { [self removeFromSuperview]; + if (finished && actions) { + actions(); + } }]; }]; } -(void)hideByTap { if (_hideOnBackgroundTap) { - [self hide]; + [self hideWithActions:nil]; } } diff --git a/Demo/.DS_Store b/Demo/.DS_Store index 34e22ddc9da215765fa56cd2653c623792fbdcae..2afbc441bc37b2b8843bbf3d996aa83d6e8a29f5 100644 GIT binary patch delta 378 zcmZoMXfc=|#>B!ku~2NHo+2aH#(>?7iv?Ji7`Z0%Fin)YlT?tCSzKaZaD$PFnT3^& zor9AL2>JLqC!b+btB(%O$S)5`ObW|PEsqxvan8>xNzBYkEdmJ#XQrekB^JemXXd5k zmpkQ`=A{(JKn24yQ%W+xnxO)m96%T^AW>ayWNfaZU}RxdtD{hDZf>BXU}9!aTPsk{ z$swt3Z10_vU(?aq)!oy(Vif~}90L$AGJ;4T5QI>0a`j|8CYi~Z%+ZWulLMJ0CQoD* z5y?q63{K9^Er2NcCIzGslDYXVE-9rY$qWn^LU=cUl^{!|;FRPq$UridF<|onW+}$a g>>T_Yz>wX{$nu?eGQWr;2hgERAX7I-h^%1-0EyRLB)qu~2NHo+2aL#(>?7jBJy6SSISPPb$dCEG{uHxW>rD%)-jX&cVsa z!4ngnnU|7Z?v!7emr@)ZoRME1oSBlElvp%*JBwO$43ra|nNpGwFCbA}ZE9(*qhMrc zSgWH@ZEkL$qhMleQCrK&!NDnTfJ0PC&&DGpv8J}JzJUP@7#Sfn122?@QB9NWSY#$o sV~yVYkxh(oV}ma9W_AvK4xrOF3vzsCp3E=e$N^Fd)X%axLSzjy02Nv^TL1t6 diff --git a/Demo/AFPopup-Demo/AFPopupView.h b/Demo/AFPopup-Demo/AFPopupView.h index b81c1ec..d243908 100644 --- a/Demo/AFPopup-Demo/AFPopupView.h +++ b/Demo/AFPopup-Demo/AFPopupView.h @@ -10,9 +10,11 @@ @interface AFPopupView : UIView +@property (nonatomic) BOOL hideOnBackgroundTap; + +(AFPopupView *)popupWithView:(UIView *)popupView; -(void)show; --(void)hide; +-(void)hideWithActions:(void (^)(void))actions; @end diff --git a/Demo/AFPopup-Demo/AFPopupView.m b/Demo/AFPopup-Demo/AFPopupView.m index 5701cf9..99aeab6 100644 --- a/Demo/AFPopup-Demo/AFPopupView.m +++ b/Demo/AFPopup-Demo/AFPopupView.m @@ -74,6 +74,9 @@ +(AFPopupView *)popupWithView:(UIView *)popupView { [view addSubview:view.backgroundShadowView]; [view addSubview:view.modalView]; + UITapGestureRecognizer *hideGesture = [[UITapGestureRecognizer alloc] initWithTarget:view action:@selector(hideByTap)]; + [view.backgroundShadowView addGestureRecognizer:hideGesture]; + return view; } @@ -128,7 +131,7 @@ -(void)show { } --(void)hide { +-(void)hideWithActions:(void (^)(void))actions { [UIView animateWithDuration:0.4 delay:0 @@ -157,10 +160,19 @@ -(void)hide { _renderImage.layer.transform = CATransform3DMakePerspective(0, 0); } completion:^(BOOL finished) { [self removeFromSuperview]; + if (finished && actions) { + actions(); + } }]; }]; } +-(void)hideByTap { + if (_hideOnBackgroundTap) { + [self hideWithActions:nil]; + } +} + -(UIImage *)imageWithView:(UIView *)view { UIGraphicsBeginImageContextWithOptions(_renderImage.frame.size, view.opaque, [[UIScreen mainScreen] scale]); diff --git a/Demo/AFPopup-Demo/ViewController.m b/Demo/AFPopup-Demo/ViewController.m index 15ba7d2..9ee1550 100644 --- a/Demo/AFPopup-Demo/ViewController.m +++ b/Demo/AFPopup-Demo/ViewController.m @@ -43,7 +43,7 @@ -(void)go { -(void)hide { - [_popup hide]; + [_popup hideWithActions:nil]; } -(void)didReceiveMemoryWarning {