简体   繁体   English

叠加层无法使用UITableView滚动-iOS

[英]Overlay not scrolling with UITableView - iOS

I have a UITableView class that uses the following methods to call a loading overlay when going to the next screen. 我有一个UITableView类,当转到下一个屏幕时,该类使用以下方法来调用加载叠加层。 The problem is that this loading screen does not scroll with the list... So if you scroll a little bit and click on something, the loading screen doesn't show (because it's at the top). 问题在于此加载屏幕不会随列表一起滚动...因此,如果您滚动一点并单击某项,则不会显示加载屏幕(因为它在顶部)。 How can I get the loading screen to stay on top of the UITableView at all times? 如何使加载屏幕始终保持在UITableView顶部? Please know that each UITableView is contained within a UINavBar, which is contained within a UITabBar. 请注意,每个UITableView都包含在UINavBar中,而UINavBar包含在UITabBar中。 Here is my code: 这是我的代码:

-(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];
}

Are you using a UITableViewController? 您正在使用UITableViewController吗?

You should be able to fix your issue by adding the overlay view to the table's superview instead of the table view itself. 您应该能够通过将叠加视图添加到表的超级视图而不是表视图本身来解决问题。 This way your overlay is actually above and separate from your scrolling table view 这样,叠加层实际上位于滚动表视图的上方并与之分离

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM