如何知道视图层次结构中是否显示UIActionSheet?

Car*_*loS 1 objective-c uiactionsheet ios

如何知道是否有UIActionSheet展示View Hierarchy?另外我想得到一个参考UIActionSheet,任何好主意?

Car*_*loS 6

请注意,在iOS6上,您需要一个递归搜索来查找UIActionSheet,它现在不是UIWindow的直接子视图.

static UIView *actionSheet = nil;
-(void)findActionSheetInSubviewsOfView:(id)view
{
    if (actionSheet) {
        return;
    }
    if ([[view valueForKey:@"subviews"] count] != 0) {
        for (id subview in [view valueForKey:@"subviews"]) {
            if ([subview isKindOfClass:[UIActionSheet class]]) {
                actionSheet = subview;
            }
            else
                [self findActionSheetInSubviewsOfView:subview];
        }
    }
}

-(UIActionSheet*) actionSheetShowing {
    actionSheet = nil;
    for (UIWindow* window in [UIApplication sharedApplication].windows) {
        [self findActionSheetInSubviewsOfView:window];
    }

    if (actionSheet) {
        return (UIActionSheet*)actionSheet;
    }
    return nil;
}
Run Code Online (Sandbox Code Playgroud)