5

我有一个 UITableView 类,它使用以下方法在进入下一个屏幕时调用加载覆盖。问题是这个加载屏幕不会随着列表滚动......所以如果你滚动一点并点击一些东西,加载屏幕不会显示(因为它在顶部)。如何让加载屏幕始终保持在 UITableView 的顶部?请注意,每个 UITableView 都包含在 UINavBar 中,而 UINavBar 又包含在 UITabBar 中。这是我的代码:

-(void)createLoadScreen
{
    CGRect screenRect = [self.view bounds];
    CGRect overlayFrame = CGRectMake(0.0, 0.0, screenRect.size.width, screenRect.size.height);
    overlay = [[UIView alloc] initWithFrame:overlayFrame];
    overlay.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.7];
    CGRect frame = CGRectMake(screenRect.size.width / 2 - 25.0, screenRect.size.height / 2 - 70, 25.0, 25.0);
    loading = [[UIActivityIndicatorView alloc] initWithFrame:frame];
    [loading setActivityIndicatorViewStyle:UIActivityIndicatorViewStyleWhiteLarge];
    [loading sizeToFit];
    loading.autoresizingMask = (UIViewAutoresizingFlexibleLeftMargin |
                                UIViewAutoresizingFlexibleRightMargin |
                                UIViewAutoresizingFlexibleTopMargin |
                                UIViewAutoresizingFlexibleBottomMargin);
    loading.hidesWhenStopped = YES;
    [overlay addSubview:loading];
}

-(void)showActivityIndicator
{ 
    [self.view addSubview:overlay];
    [loading startAnimating];
}

-(void)removeActivityIndicator {
    [loading stopAnimating];
    [overlay removeFromSuperview];
}
4

1 回答 1

5

你在使用 UITableViewController 吗?

您应该能够通过将覆盖视图添加到表的超级视图而不是表视图本身来解决您的问题。这样,您的叠加层实际上位于滚动表视图之上并与滚动表视图分开

-(void)showActivityIndicator
{ 
    [[self.view superview] addSubview:overlay];
    [loading startAnimating];
}
于 2012-05-03T00:12:04.753 回答