UITableViewController中的UIActivityIndi​​catorView

Dou*_*las 1 objective-c uitableview uiactivityindicatorview ios

我目前正在更新我的一个应用程序.它从Internet获取信息,并使用networkActivityIndi​​catorVisible显示和隐藏状态栏中的活动指示器.我们收到的一个抱怨是,它太小了,用户不知道他们的设备正在获取信息.所以我的想法是在我的视野中使用旋转活动轮.如果你试图从项目中拖出一个,它会将它放在一个单元格中,或者放在我制作的标题UIView中.这不是我想要的,所以我以编程方式制作它.

在头文件中.

@property (strong, nonatomic) UIActivityIndicatorView *mySpinner;
Run Code Online (Sandbox Code Playgroud)

在实现文件中.

_mySpinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
_mySpinner.color = [UIColor blackColor];
_mySpinner.translatesAutoresizingMaskIntoConstraints = NO;
_mySpinner.hidesWhenStopped = YES;
Run Code Online (Sandbox Code Playgroud)

然后我通过执行以下操作将旋转轮添加到我的视图中.随着我的约束.

[self.view addSubview:_mySpinner];

[self.view addConstraint:[NSLayoutConstraint constraintWithItem:_mySpinner
                                                      attribute:NSLayoutAttributeCenterX
                                                      relatedBy:NSLayoutRelationEqual
                                                         toItem:self.view
                                                      attribute:NSLayoutAttributeCenterX
                                                     multiplier:1
                                                       constant:0]];
[self.view addConstraint:[NSLayoutConstraint constraintWithItem:_mySpinner
                                                      attribute:NSLayoutAttributeCenterY
                                                      relatedBy:NSLayoutRelationEqual
                                                         toItem:self.view
                                                      attribute:NSLayoutAttributeCenterY
                                                     multiplier:0.75
                                                       constant:0]];
[_mySpinner startAnimating];
Run Code Online (Sandbox Code Playgroud)

我运行代码,它工作正常.即使我旋转旋转器也是我想要的地方.然而,这就是问题所在,当我滚动表格视图时,微调器随之而来!

我知道这是因为我将微调器添加到self.view并使用self.view进行了所有约束.在UITableViewController的情况下,表视图是self.view.

该应用程序有几个表格视图,它们都很长,很多都有自定义单元格.我真的不想重新设计所有内容,但是有没有人知道UITableViewController是否有超级视图我可以将我的约束放到?我尝试了几件事,但没有任何工作.抱歉这么长的问题,但我希望有人可以提供帮助.谢谢阅读!

san*_*ali 6

解决方案只是访问您的应用程序的窗口然后附加活动指示器就像

 UIWindow *frontWindow = [[UIApplication sharedApplication] keyWindow];
    self.activity.center=frontWindow.center;

    [frontWindow addSubview:self.activity];
    [self.activity startAnimating];
Run Code Online (Sandbox Code Playgroud)

链接到代码https://github.com/murali9/ActvityonTableview