#import <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
@interface UIAlertController (TapGesAlertController)
- (void)tapGesAlert;
@end
#import "UIAlertController+TapGesAlertController.h"
@implementation UIAlertController (TapGesAlertController)
- (void)tapGesAlert{
NSArray * arrayViews = [UIApplication sharedApplication].keyWindow.subviews;
if (arrayViews.count>0) {
//array會(huì)有兩個(gè)對(duì)象屏镊,一個(gè)是UILayoutContainerView依疼,另外一個(gè)是UITransitionView,我們找到最后一個(gè)
UIView * backView = arrayViews.lastObject;
backView.userInteractionEnabled = YES;
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tap)];
[backView addGestureRecognizer:tap];
}
}
-(void)tap
{
[self dismissViewControllerAnimated:YES completion:nil];
}
@end