【问题标题】:How to show loading spinner of LGButton before executing function on click?如何在单击执行功能之前显示 LGButton 的加载微调器?
【发布时间】:2020-11-06 03:51:25
【问题描述】:

我使用的是 https://github.com/loregr/LGButton 。我得到了触发功能等的按钮,但是如何使用这个库的加载微调器 UI?一旦我也启用它,它只会显示几毫秒,因为单击按钮时会快速触发该功能

@IBAction func theFunction(_ sender: LGButton) {
       
        let alertView = SCLAlertView()
        alertView.addButton("Y button", target: self, selector: #selector(self.generateNewNumber))
        alertView.addButton("X Button", target: self, selector: #selector(self.zfunction))

        alertView.showSuccess("", subTitle: ""])

    }
  
    
    @IBOutlet var instanceofLGButton: LGButton!
    
    
    override func viewDidLoad() {
        super.viewDidLoad()
        navigationController?.interactivePopGestureRecognizer?.isEnabled = true
        self.view.backgroundColor = UIColor.black 
        instanceofLGButton.addTarget(self, action: #selector(self.learning(_:)), for: .touchUpInside)

谢谢。相关部分代码如上。

【问题讨论】:

标签: ios swift button time delay


【解决方案1】:

isLoading参数设置为true时,会显示微调器。

    @IBAction func action(_ sender: LGButton) {
        sender.isLoading = true
        let deadlineTime = DispatchTime.now() + .seconds(3)
        DispatchQueue.main.asyncAfter(deadline: deadlineTime) {
            sender.isLoading = false
            // DO SOMETHING
        }
    }

【讨论】:

  • 非常感谢。这行得通。我尝试只使用 DispatchQueue without.main.asyncAfter 以完全相同的方式使用 DO SOMETHING 操作,但没有 sender.isLoading。从哪里 isLoading 一个函数。它在 Apple Docs 中吗?可以链接吗?谢谢@delavega66 你从哪里得到的 isLoading?
  • 不,它是第三方库。我是从LGButton 示例项目中获得的。
猜你喜欢
  • 1970-01-01
  • 2016-08-19
  • 1970-01-01
  • 2020-06-09
  • 2018-09-28
  • 2017-01-19
  • 2011-08-11
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多