- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用 cosmicmind material swift 库,并按照示例代码尝试让 FAB MenuView 正常工作。
我已经复制了代码并添加了我想要的按钮,为了测试我只是用 2 个按钮进行测试。我面临的问题是 handleMenu
函数:
/// Handle the menuView touch event.
internal func handleMenu() {
if menuView.menu.opened {
menuView.close()
(menuView.menu.views?.first as? MaterialButton)?.animate(MaterialAnimation.rotate(rotation: 0))
} else {
menuView.menu.open() { (v: UIView) in
(v as? MaterialButton)?.pulse()
}
(menuView.menu.views?.first as? MaterialButton)?.animate(MaterialAnimation.rotate(rotation: 0.125))
}
}
此 UINavigationController 的完整代码:
import UIKit
import Material
class MyTeeUpsController: UINavigationController {
/// MenuView reference.
private lazy var menuView: MenuView = MenuView()
/// Default spacing size
let spacing: CGFloat = 16
/// Diameter for FabButtons.
let diameter: CGFloat = 56
/// Handle the menuView touch event.
internal func handleMenu() {
if menuView.menu.opened {
menuView.close()
(menuView.menu.views?.first as? MaterialButton)?.animate(MaterialAnimation.rotate(rotation: 0))
} else {
menuView.menu.open() { (v: UIView) in
(v as? MaterialButton)?.pulse()
}
(menuView.menu.views?.first as? MaterialButton)?.animate(MaterialAnimation.rotate(rotation: 0.125))
}
}
/// Handle the menuView touch event.
internal func handleButton(button: UIButton) {
print("Hit Button \(button)")
}
private func prepareMenuView() {
//let w: CGFloat = 52
var img:UIImage? = MaterialIcon.cm.add?.imageWithRenderingMode(.AlwaysTemplate)
let button1: FabButton = FabButton()//frame: CGRectMake((view.bounds.width - w)-10, 550,w,w))
button1.setImage(img, forState: .Normal)
button1.setImage(img, forState: .Highlighted)
button1.pulseColor = MaterialColor.blue.accent3
button1.backgroundColor = MaterialColor.blueGrey.lighten1
button1.borderColor = MaterialColor.blue.accent3
button1.borderWidth = 1
button1.addTarget(self, action: #selector(handleMenu), forControlEvents: .TouchUpInside)
menuView.addSubview(button1)
img = UIImage(named: "filing_cabinet")?.imageWithRenderingMode(.AlwaysTemplate)
let button2:FabButton = FabButton()
button2.depth = .None
button2.setImage(img, forState: .Normal)
button2.setImage(img, forState: .Highlighted)
button2.pulseColor = MaterialColor.blue.accent3
button2.borderColor = MaterialColor.blue.accent3
button2.borderWidth = 1
button2.backgroundColor = MaterialColor.blueGrey.lighten1
button2.addTarget(self, action: #selector(handleButton), forControlEvents: .TouchUpInside)
menuView.addSubview(button2)
menuView.menu.direction = .Up
menuView.menu.baseSize = CGSizeMake(diameter, diameter)
menuView.menu.views = [button1,button2]
view.layout(menuView).width(diameter).height(diameter).bottomRight(bottom: 58, right: 20)
}
private func prepareTabBarItem() {
//todo
}
override func viewDidLoad() {
super.viewDidLoad()
prepareMenuView()
}
}
我作为 UINavigationController 的 subview 嵌入的菜单。我添加到这个 subview 的原因是因为 FAB 位于搜索/显示 Controller (TableView) 之上,这样即使滚动表格的内容,FAB 也可以保持在 TableView 之上。
当 View 最初加载时,我可以单击菜单按钮,动画正确发生并出现 button2。但是,它不允许我点击第二个按钮或再次按下 button1 关闭菜单,除非我导航到选项卡栏 Controller 中的另一个选项卡,然后导航回 FAB MenuView 所在的选项卡。我在 viewDidLoad
中加载我的 prepareMenuView()
函数,正如示例中所示。
不确定如何修改它以便它可以按预期运行。选择另一个 ViewController 生命周期方法来运行 prepareMenuView()
没有意义。
最佳答案
所以您的代码的问题是 button2
只有 handleButton
的选择器处理程序。 handleMenu
处理程序未添加到其中。所以你有两个解决方案。
handleMenu
调用添加到 handleButton
内部函数句柄按钮(按钮:UIButton){
打印(“点击按钮\(按钮)”)
handleMenu(按钮)
}
handleMenu
的 button2
实例。
button2.addTarget( self , Action :#selector(handleMenu),forControlEvents:.TouchUpInside)
button2.addTarget( self , Action :#selector(handleButton),forControlEvents:.TouchUpInside)
任一选项都可以,请记住顺序很重要。因此,如果您希望在加载某些内容之前关闭菜单,请在添加 handleButton
之前调用方法或添加选择器处理程序 handleMenu
。
:) 一切顺利!
关于ios - cosmicmind Material swift MenuView 不关闭,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39273816/
我注意到在 SwiftUI 中只能有一个 .popover 修饰符。我必须呈现两个可能的简单弹出窗口,其中一个是 MenuView,另一个是 CreateChannelView。 为此我有: @Sta
我正在使用 cosmicmind material swift 库,并按照示例代码尝试让 FAB MenuView 正常工作。 我已经复制了代码并添加了我想要的按钮,为了测试我只是用 2 个按钮进行测
我已经更新了我的 eclipse 版本:4.2.2 和带有 API 23 的 android SDK。当我创建一个应用程序时,出现这样的错误。 [2015-10-12 17:03:05 - appco
我创建了一个应用程序,但在尝试运行时,出现这样的错误。 ERROR: In MenuView, unable to find attribute android:preserveIconSpacin
NSMenuItemCell 的两个方法 -[NSMenuItemCell menuView] 和 -[NSMenuItemCell setMenuView:] 的 64 位替代是什么类(class)
我是一名优秀的程序员,十分优秀!