我正在尝试将按钮中的一大堆代码移到单个文件中。
这是我原始VC中的按钮

    let blackView = UIView()
    let settingsLuancher = SettingsLauncher()

    @IBAction func refreshBtnAction(_ sender: UIButton) {

      SettingsLauncher.showSettings()

    }

这是SettingsLauncher.swift,
import Foundation
import UIKit

class SettingsLauncher:NSObject {

let blackView = UIView()

func showSettings() {
    if let window = UIApplication.shared.keyWindow{
        blackView.backgroundColor = UIColor(white: 0, alpha: 0.5)
        window.addSubview(blackView)
        blackView.frame = window.frame
        blackView.alpha = 0

        blackView.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(handleDismiss)))

        UIView.animate(withDuration: 0.2, animations: {
            self.blackView.alpha = 1
        })
    }

}

func handleDismiss(){
    UIView.animate(withDuration: 0.2, animations: {
        self.blackView.alpha = 0
        // dismisses blackView
    })
}

编译不断失败,并显示:
实例成员'showSettings'不能用于'SettingsLauncher'类型;您的意思是改用这种类型的值吗?

不知道为什么会这样,任何帮助表示赞赏。

最佳答案

您正在使用类名SettingsLauncher,而不是对象settingsLuancher:

SettingsLauncher.showSettings()

应该
settingsLuancher.showSettings()

10-08 15:45