在 CosmicMind / Material 库中,我如何启动(显示)snackbar?
我试图准备snackbarController,然后在用户单击按钮时显示它。
如他们的示例所示:
private var undoButton: FlatButton!
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
prepareSnackbar()
animateSnackbar()
}
@IBAction func loginBtnTapped(_ sender: AnyObject) {
sc?.show(vc: UIViewControlle, sender: Any)//doesn't show
more code... (which works)
}
private func prepareUndoButton() {
undoButton = FlatButton(title: "Undo", titleColor: Color.yellow.base)
undoButton.pulseAnimation = .backing
undoButton.titleLabel?.font = RobotoFont.regular(with: 14)
}
private func prepareSnackbar() {
guard let sc = snackbarController else {
return
}
sc.snackbar.text = "Reminder saved."
sc.snackbar.rightViews = [undoButton]
}
private func animateSnackbar() {
guard let sc = snackbarController else {
return
}
_ = sc.animate(snackbar: .visible, delay: 1)
_ = sc.animate(snackbar: .hidden, delay: 4)
}
所以我确实在一个空项目上尝试过,但小吃店仍然无法正常工作。你能指出我做错了什么吗?
import Foundation
import UIKit
import Material
class MainViewController: UIViewController {
private var undoButton: FlatButton!
open override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = Color.red.accent1
prepareUndoButton()
}
open override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
//prepareSnackbar()
//animateSnackbar()
}
private func prepareUndoButton() {
undoButton = FlatButton(title: "Undo", titleColor: Color.yellow.base)
undoButton.pulseAnimation = .backing
undoButton.titleLabel?.font = RobotoFont.regular(with: 14)
}
private func prepareSnackbar() {
guard let sc = snackbarController else {
return
}
sc.snackbar.text = "Reminder saved."
sc.snackbar.rightViews = [undoButton]
}
private func animateSnackbar() {
guard let sc = snackbarController else {
return
}
_ = sc.animate(snackbar: .visible, delay: 1)
_ = sc.animate(snackbar: .hidden, delay: 4)
}
@IBAction func testBtn(_ sender: AnyObject) {
print("TEST TEST TEST")
prepareSnackbar()
animateSnackbar()
}
}