使用UITableView - iOS覆盖不滚动

时间:2012-05-03 00:04:48

标签: objective-c ios uitableview scroll overlay

我有一个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];
}

1 个答案:

答案 0 :(得分:5)

您使用的是UITableViewController吗?

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

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