Skip to content

Instantly share code, notes, and snippets.

@chrishulbert
Created May 30, 2011 05:34
Show Gist options
  • Save chrishulbert/998492 to your computer and use it in GitHub Desktop.
Save chrishulbert/998492 to your computer and use it in GitHub Desktop.
Allow closing a UIActionSheet by tapping above it, in the shaded area
// For detecting taps outside of the alert view
-(void)tapOut:(UIGestureRecognizer *)gestureRecognizer {
CGPoint p = [gestureRecognizer locationInView:self];
if (p.y < 0) { // They tapped outside
[self dismissWithClickedButtonIndex:0 animated:YES];
}
}
-(void) showFromTabBar:(UITabBar *)view {
[super showFromTabBar:view];
// Capture taps outside the bounds of this alert view
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapOut:)];
tap.cancelsTouchesInView = NO; // So that legit taps on the table bubble up to the tableview
[self.superview addGestureRecognizer:tap];
[tap release];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment