0

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.

4

1 回答 1

1

这是一些关于如何显示 UIAlertView 并自动关闭它的示例代码。

展示下:

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

忽略它:

- (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];
            }
}

你可以在几秒钟后调用dismiss方法:

[self performSelector:@selector(dismiss) withObject:nil afterDelay:1.0 inModes:nil];
于 2013-09-04T12:44:09.947 回答