Sumi-Interactive / SIAlertView

An UIAlertView replacement with block syntax and fancy transition styles.
MIT License
2.51k stars 424 forks source link

Close SIAlertView by touch outside of it #59

Open winkelsdorf opened 10 years ago

winkelsdorf commented 10 years ago

Enhancement req. as in the title.

Let the user close the SIAlertView by touching/clicking outside the SIAlertView UIView.

winkelsdorf commented 10 years ago

As of now a workaround:

#pragma mark - SIAlterView Private Property Access

@interface SIAlertView ()
@property (nonatomic, strong) UIView *containerView;
@end

...

// before show, after creating the SIAlertView instance and setting the buttons etc:

  UITapGestureRecognizer *tapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(dismissQuickAccess:)];
  tapRecognizer.cancelsTouchesInView = NO;
  [quickAccessView addGestureRecognizer:tapRecognizer];

  [quickAccessView show];

and Tap Handling as the following:

- (void)dismissQuickAccess:(UITapGestureRecognizer *)gestureRecognizer
{
    // dismiss Quick Access when touching outside of it
    CGPoint point = [gestureRecognizer locationInView:self.view];
    if (!CGRectContainsPoint(quickAccessView.containerView.frame, point))
    {
        [quickAccessView dismissAnimated:YES];
    }
}

quickAccessView is just a private declaration for an SIAlertView:

    SIAlertView *quickAccessView;

Cheers

NikKovIos commented 8 years ago

Need this feature!

NikKovIos commented 8 years ago

I've added a pull request with this update https://github.com/Sumi-Interactive/SIAlertView/pull/129