搜索视图控制器推送 VC 时,活动指示器不会出现在自定义 UIAlertView 的中心
Posted
技术标签:
【中文标题】搜索视图控制器推送 VC 时,活动指示器不会出现在自定义 UIAlertView 的中心【英文标题】:Activity Indicator not appears center on custom UIAlertView when search view controller push ups VC 【发布时间】:2019-01-09 06:16:49 【问题描述】:我想在包含表格视图的 UIAlertViewController 上显示活动指示器,因此它可以正常工作,但第二种情况是当搜索控制器出现在 UIAlertViewController 的父级上时,活动指示器不会出现在 UIAlertViewController 的中心。
在将 searchVC 附加到父级之前附加图像
当 searchVC 添加到 Parent 时,然后
以下是活动指标代码
var actInd: UIActivityIndicatorView = UIActivityIndicatorView()
func startActivityIndicator()
self.view.isUserInteractionEnabled = false
let loadingView: UIView = UIView()
loadingView.frame = CGRect(x: 0, y: 0, width: 80.0, height: 80.0)
loadingView.center = self.view.center
loadingView.backgroundColor = UIColor(red: 44/255, green: 44/255, blue: 44/255, alpha: 0.7)
loadingView.clipsToBounds = true
loadingView.layer.cornerRadius = 10
actInd.frame = CGRect(x: 0, y: 0, width: 40.0, height: 40.0)
actInd.style = .whiteLarge
actInd.center = CGPoint(x: loadingView.frame.size.width / 2, y: loadingView.frame.size.height / 2)
loadingView.addSubview(actInd)
self.view.addSubview(loadingView)
actInd.startAnimating()
func stopActivityIndicator()
self.view.isUserInteractionEnabled = true
actInd.stopAnimating()
let view = actInd.superview
view?.removeFromSuperview()
我在UIViewController
的扩展中添加了以上代码
【问题讨论】:
【参考方案1】:最后通过以下方式设置约束解决了
func startActivityIndicator()
self.view.isUserInteractionEnabled = false
let loadingView: UIView = UIView()
loadingView.translatesAutoresizingMaskIntoConstraints = false
actInd.translatesAutoresizingMaskIntoConstraints = false
self.view.addSubview(loadingView)
loadingView.addSubview(actInd)
loadingView.centerXAnchor.constraint(equalTo: self.view.centerXAnchor).isActive = true
loadingView.centerYAnchor.constraint(equalTo: self.view.centerYAnchor).isActive = true
loadingView.widthAnchor.constraint(equalToConstant: 80.0).isActive = true
loadingView.heightAnchor.constraint(equalToConstant: 80.0).isActive = true
loadingView.center = self.view.center
loadingView.backgroundColor = UIColor(red: 44/255, green: 44/255, blue: 44/255, alpha: 0.7)
loadingView.clipsToBounds = true
loadingView.layer.cornerRadius = 10
actInd.leadingAnchor.constraint(equalTo: loadingView.leadingAnchor).isActive = true
actInd.trailingAnchor.constraint(equalTo: loadingView.trailingAnchor).isActive = true
actInd.topAnchor.constraint(equalTo: loadingView.topAnchor).isActive = true
actInd.bottomAnchor.constraint(equalTo: loadingView.bottomAnchor).isActive = true
actInd.style = .whiteLarge
actInd.center = CGPoint(x: loadingView.frame.size.width / 2, y: loadingView.frame.size.height / 2)
actInd.startAnimating()
【讨论】:
以上是关于搜索视图控制器推送 VC 时,活动指示器不会出现在自定义 UIAlertView 的中心的主要内容,如果未能解决你的问题,请参考以下文章
关闭没有 NavigationController 的推送视图控制器