0

我试图从 UIView 中删除指标子视图,但它同时删除了它们,而不仅仅是 subview 。

我的观点是:

 UIView * aView = [[UIView alloc] initWithFrame:CGRectMake(0.5*winSize.width-winSize.width/3, 0.85*winSize.height , winSize.width/1.5, winSize.width/8)];
    aView.backgroundColor = [UIColor clearColor];
    aView.tag  = 31000;
    UIActivityIndicatorView  *av = [[[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite] autorelease];
    av.frame=aView.bounds;
    [av setBackgroundColor:[UIColor colorWithRed:0.23 green:0.23 blue:0.23 alpha:0.85]];
    av.layer.cornerRadius=4;
    av.tag = 31001;
    [aView addSubview:av];
    [[[CCDirector sharedDirector]view]addSubview:aView];
    [av startAnimating];

我试图用我在这里找到的许多方法来删除它:

 UIActivityIndicatorView *tmpimg = (UIActivityIndicatorView *)[[[CCDirector sharedDirector]view] viewWithTag:31001];
    if(tmpimg)
        [((UIView *)tmpimg) removeFromSuperview];

或者

   UIView *removeView;
    while((removeView = [[[CCDirector sharedDirector]view] viewWithTag:31001]) != nil)
    {
        [removeView removeFromSuperview];
    }

或者

 UIView * aView = [[[CCDirector sharedDirector]view] viewWithTag:31000];
    if(aView)
        for(UIView *subview in [aView subviews])
            [subview removeFromSuperview];

但它总是删除他们两个......我迷路了..

4

1 回答 1

3

这将从您的视图中删除任何 UIActivityIndi​​catorView ,而无需对其进行标记 imo 是一个糟糕的解决方案

for (UIView *aSubView in aView) {
    if ([aSubView isKindOfClass:[UIActivityIndicatorView class]])
        [aSubView removeFromSuperview];
}
于 2013-04-24T11:34:01.910 回答