1

快速提问!对不起,提前noobiness。我最近开始开发 iOS 应用程序并想加载一个用于单击按钮的视图。我在swift4工作。

 @IBAction func btnAddItem_AddDrinks_Click(_ sender: Any) {
        //[self dismissViewControllerAnimated:YES completion:nil];
        //[self.navigationController popViewControllerAnimated:YES];
        if strIsSpecial == nil {
            ValidationString.sharedManager().showAlert(withTitle: "", messageBody: "Please select either Regular, Special or Free")
        }
        else if ValidationString.sharedManager().isNullString(txtfldOunce.text!) == true {
          //  ValidationString.sharedManager().showAlert(withTitle: ALERT_TITLE, messageBody: "Ounce" + (ALERT_FIELD_SHOULD_NOT_BLANK))

            let alert = UIAlertController(title: "Alert", message: "Ounces shouldn't be left blank", preferredStyle: UIAlertControllerStyle.alert)
            alert.addAction(UIAlertAction(title: "Click", style: UIAlertActionStyle.default, handler: nil))
            self.present(alert, animated: true, completion: nil)
        }
        else if ValidationString.sharedManager().isNullString(txtfldUserReference_AddDrinks.text!) == true {

            let alert = UIAlertController(title: "Alert", message: "Drink Name shouldn't be left blank", preferredStyle: UIAlertControllerStyle.alert)
            alert.addAction(UIAlertAction(title: "Click", style: UIAlertActionStyle.default, handler: nil))
            self.present(alert, animated: true, completion: nil)

            //ValidationString.sharedManager().showAlert(withTitle: ALERT_TITLE, messageBody: "Drink Name" + (ALERT_FIELD_SHOULD_NOT_BLANK))
        }
        else {
            if view_Loading != nil {
                view_Loading?.removeFromSuperview()
                view_Loading = nil
                obj_LoadView = nil
            }
            obj_LoadView = LoadView(frame: <#CGRect#>)
            view_Loading = obj_LoadView?.showActivity("Loading....")
            view.addSubview(view_Loading!)
            view.isUserInteractionEnabled = false

当前的错误是 obj_LoadView = LoadView(frame: <#CGRect#>) 的“编辑器是占位符”。我知道我需要为 CGRect 放一些东西,但不确定是什么。任何帮助表示赞赏,谢谢!

4

2 回答 2

2

我个人喜欢创建自己的activityIndi​​catorView

class LoadingView: UIView {
    
    private var activityIndicatorView: UIActivityIndicatorView {
        
        let view = UIActivityIndicatorView(activityIndicatorStyle: .white)
        view.startAnimating()
        
        view.center = self.center
        return view
    }
    
    private var isPresenting: Bool = false
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        self.backgroundColor = .black
        self.alpha = 0.0
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    
    func present() {
        guard let window = UIApplication.shared.keyWindow else { return }
        window.addSubview(self)
        fadeIn()
    }
    
    func dismiss() {
        guard isPresenting == true else { return }
        fadeOut()
    }
    
    private func fadeIn() {
        UIView.animate(withDuration: 0.25, delay: 0.0, options: .curveEaseInOut, animations: {
            self.alpha = 0.5
        }) { (bool: Bool) in
            self.addSubview(self.activityIndicatorView)
            self.isPresenting = true
        }
    }
    
    private func fadeOut() {
        UIView.animate(withDuration: 0.25, delay: 0.0, options: .curveEaseInOut, animations: {
            self.alpha = 0.0
        }) { (bool: Bool) in
            self.removeFromSuperview()
            self.isPresenting = false
        }
    }
}

于 2017-12-08T12:47:09.893 回答
2

当您开始输入时,Xcode 将为您自动完成语句。如果您不更改自动完成的参数,您将收到该错误。

问题是这里的这一行:

obj_LoadView = LoadView(frame: <#CGRect#>)

<#CGRect#>需要使用实际的 CGRect 而不是占位符进行更改。

将 CGRect 设置为您想要的新视图的大小:

obj_LoadView = LoadView(frame: CGRect(x: 0.0, y: 0.0, width: 400.0, height: 400))

这将使视图的框架为 400x400 点。

如果要使视图成为其所在视图的完整大小,可以执行以下操作:

obj_LoadView = LoadView(frame: view.frame)
于 2017-11-04T19:56:30.373 回答