使用UITableView - iOS覆盖不滚动 [英] Overlay not scrolling with UITableView - iOS

查看:113
本文介绍了使用UITableView - iOS覆盖不滚动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a UITableView class that uses the following methods to call a loading overlay when going to the next screen. 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? Please know that each UITableView is contained within a UINavBar, which is contained within a 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];
}


推荐答案

您使用的是UITableViewController吗?

Are you using a 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];
}

这篇关于使用UITableView - iOS覆盖不滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆