快速提问!对不起,提前菜鸟。我最近开始开发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(帧:<#CGRect#>)。我知道我需要为CGRect放一些东西,但不确定是什么。任何帮助不胜感激,谢谢!
当您开始键入时,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)
我个人喜欢创建自己的活动指示器视图
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
}
}
}