在 CosmicMind / Material SnackbarController 中,如何启动(显示)小吃店?
In CosmicMind / Material SnackbarController, how do I start (show) the snackbar?
在 CosmicMind / Material 库中,如何启动(显示)快餐栏?
我尝试准备 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)
}
所以我确实在一个空项目上尝试过,但 snackbar 仍然不起作用。你能指出我做错了什么吗?
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()
}
}
如果您注意到在 viewDidAppear
函数中有一个 animateSnackbar
调用,它调用行
_ = sc.animate(snackbar: .visible, delay: 1)
_ = sc.animate(snackbar: .hidden, delay: 4)
您基本上可以在按钮处理程序中使用 animateSnackbar
函数,如下所示:
@IBAction func loginBtnTapped(_ sender: AnyObject) {
animateSnackbar()
}
就是这样。有两种动画在播放,一种用于显示,一种用于隐藏小吃店。设置您希望它们自动出现和隐藏的延迟时间。
您可能希望从 viewDidAppear
方法中删除 animateSnackbar
调用,因为它是为示例放在那里的。
在 CosmicMind / Material 库中,如何启动(显示)快餐栏?
我尝试准备 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)
}
所以我确实在一个空项目上尝试过,但 snackbar 仍然不起作用。你能指出我做错了什么吗?
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()
}
}
如果您注意到在 viewDidAppear
函数中有一个 animateSnackbar
调用,它调用行
_ = sc.animate(snackbar: .visible, delay: 1)
_ = sc.animate(snackbar: .hidden, delay: 4)
您基本上可以在按钮处理程序中使用 animateSnackbar
函数,如下所示:
@IBAction func loginBtnTapped(_ sender: AnyObject) {
animateSnackbar()
}
就是这样。有两种动画在播放,一种用于显示,一种用于隐藏小吃店。设置您希望它们自动出现和隐藏的延迟时间。
您可能希望从 viewDidAppear
方法中删除 animateSnackbar
调用,因为它是为示例放在那里的。