搜索视图控制器上推VC时,活动指示器未出现在自定义UIAlertView的中心

时间:2019-01-09 06:16:49

标签: ios swift4 uialertview uisearchcontroller uiactivityindicatorview

我想在包含表视图的UIAlertViewController上显示活动指示器,因此其工作正常,但是第二种情况是,当搜索控制器出现在UIAlertViewController的父项上时,活动指示器没有出现在UIAlertViewController的中央。 / strong>

在父级上附加searchVC之前附加图像 output on custom alertview controller , without adding search VC on parent VC

然后当searchVC添加到Parent时,然后activity indicator goes up of custom alertVC

以下是活动指标代码

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 个答案:

答案 0 :(得分:0)

最后通过按照以下方式设置约束来解决它

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()
}