简体   繁体   中英

UIActionSheet pass touches through?

I'm looking to use a UIActionSheet kind of like a contextual message box (with no action buttons at all and just a label in the bubble with an arrow pointing at something). Since there are no actions the user can take, I would like it to not require a tap to dismiss, but I can't see any way (such as a passthroughViews property) to allow this.

It's probably not designed for this, but it does happen to be handy for it.

This is some example code of how to show an UIAlertView and dismiss it automatically.

Show it:

- (void)show 
{
     UIAlertView* alert = [[UIAlertView alloc] initWithTitle:@"title"
                                               delegate:self
                                      cancelButtonTitle:nil
                                      otherButtonTitles:nil];
     alert.tag = tag;
     [alert show];
}

Dismiss it:

- (void)dismiss
{
    for (UIWindow* w in [UIApplication sharedApplication].windows)
        for (NSObject* o in w.subviews)
            if ([o isKindOfClass:[UIAlertView class]]) {
                UIAlertView *alert = (UIAlertView*) o;
                if (alert.tag == tag)
                    [alert dismissWithClickedButtonIndex:[(UIAlertView*)o cancelButtonIndex] animated:YES];
            }
}

Yo can call the dismiss method after a couple of seconds:

[self performSelector:@selector(dismiss) withObject:nil afterDelay:1.0 inModes:nil];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM