【问题标题】:UIView does not show properly when the uitableview is scrolled down向下滚动 uitableview 时,UIView 无法正确显示
【发布时间】:2014-05-16 02:10:55
【问题描述】:

我正在实现某种加载屏幕,其中包含一个黑色 uiview,其中心有一个微调器。

当tableview被向下滚动加载时,加载屏幕在顶部,如果tableview已经滚动到底部,加载屏幕消失。

功能

UIView *blackScreen = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
blackScreen.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.5];
blackScreen.tag = LOADING_SCREEN_TAG;

UIActivityIndicatorView *spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];

spinner.center = CGPointMake(CGRectGetWidth(self.view.bounds)/2,
                             CGRectGetHeight(self.view.bounds)/2.3);

spinner.tag = SPINNER_TAG;

[spinner startAnimating];

[self.view addSubview:blackScreen];
[self.view addSubview:spinner];

[self.view setUserInteractionEnabled:NO];

【问题讨论】:

    标签: objective-c uitableview uiview


    【解决方案1】:

    你需要加contentOffset,我想给你介绍这个page,它解释了它的使用。

    无论如何,这里是解决方案,这是假设你的tableview的变量名是tableView并且被设置为类的属性:

    CGRect loadingScreenFrame = CGRectMake([[UIScreen mainScreen] bounds].origin.x + self.tableView.contentOffset.x,
                                           [[UIScreen mainScreen] bounds].origin.y + self.tableView.contentOffset.y,
                                           [[UIScreen mainScreen] bounds].size.width,
                                           [[UIScreen mainScreen] bounds].size.height);
    
    UIView *blackScreen = [[UIView alloc] initWithFrame:loadingScreenFrame];
    blackScreen.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.5];
    blackScreen.tag = LOADING_SCREEN_TAG;
    
    UIActivityIndicatorView *spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
    
    spinner.center = CGPointMake((CGRectGetWidth(self.view.bounds)/2) + self.tableView.contentOffset.x,
                                 (CGRectGetHeight(self.view.bounds)/2.3) + self.tableView.contentOffset.y);
    
    spinner.tag = SPINNER_TAG;
    
    [spinner startAnimating];
    
    [self.view addSubview:blackScreen];
    [self.view addSubview:spinner];
    
    [self.view setUserInteractionEnabled:NO];
    

    【讨论】:

    • 如果回答了您的问题,请点击我的回答旁边的勾选按钮,以供以后访问者参考
    【解决方案2】:

    一个解决方案是不将旋转视图添加到 tableview,而是添加到它的 superview。看起来您可能正在使用 UITableViewController,这意味着您需要重组代码以使用 UIViewController 来完成这项工作。将 UITableView 和微调器视图都添加到 UIViewController 的视图中也可以实现您正在寻找的内容,而无需根据内容偏移设置中心。

    【讨论】:

      猜你喜欢
      • 2019-01-12
      • 1970-01-01
      • 2014-10-20
      • 2017-08-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-03-01
      相关资源
      最近更新 更多