1

如何知道是否有UIActionSheet演出View Hierarchy?我也想参考一下UIActionSheet,有什么好主意吗?

4

1 回答 1

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;
}
于 2013-01-15T12:24:07.737 回答