问题描述
希望在 Swift 中为我正在开发的 iOS 应用程序创建一个浮动菜单.沿着小红圈菜单的线条,如下图所示.
我最初的想法是扩展 UIViewController 类并在那里添加相应的绘图/逻辑,但是,该应用程序由一些其他控制器组成,更具体地说是 UITableViewController,它本身扩展了 UIViewController.也许有一个扩展的好地方?或者有没有更雄辩的方式在特定视图上绘制菜单而无需大量重复菜单相关代码?
菜单本身将显示在大多数屏幕上,因此我需要有选择地启用它.它也会根据用户当前所在的视图/屏幕在一定程度上与上下文相关.
有什么很棒的想法吗?
你可以用动画和所有东西创建你自己的,或者你可以查看这个库
Looking to create a floating menu in Swift for an iOS application I am developing. Something along the lines of the little red circle menu as shown in the following image.
My initial thoughts were to extend the UIViewController class and add the respective drawing/logic there, however, the application is comprised of a few other controllers, more specifically the UITableViewController which in itself extends UIViewController. Is there perhaps a good place for an extension perhaps? Or is there a more eloquent way of drawing the menu on specific views without the mass duplication of menu related code?
The menu itself will be shown on most screens, so I need to selectively enable it. It'll also be somewhat contextual based on the view/screen the user is currently on.
Any awesome ideas?
You can create your own with the animations and all the things, or you can check this library
https://github.com/lourenco-marinho/ActionButton
var actionButton: ActionButton!
override func viewDidLoad() {
super.viewDidLoad()
let twitterImage = UIImage(named: "twitter_icon.png")!
let plusImage = UIImage(named: "googleplus_icon.png")!
let twitter = ActionButtonItem(title: "Twitter", image: twitterImage)
twitter.action = { item in println("Twitter...") }
let google = ActionButtonItem(title: "Google Plus", image: plusImage)
google.action = { item in println("Google Plus...") }
actionButton = ActionButton(attachedToView: self.view, items: [twitter, google])
actionButton.action = { button in button.toggleMenu() }
}
这篇关于在 iOS 应用程序中创建浮动菜单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!