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 34e22dd..2afbc44 100644 Binary files a/Demo/.DS_Store and b/Demo/.DS_Store differ 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 {