在iOS应用程序中创build一个浮动菜单

寻找在Swift中为我正在开发的iOS应用程序创build一个浮动菜单。 如下图所示,沿着小红圈菜单的行。

在这里输入图像说明

我最初的想法是扩展UIViewController类,并在那里添加相应的绘图/逻辑,但是,应用程序是由一些其他控制器组成,更具体地说是UITableViewController,它本身扩展了UIViewController。 也许有一个扩展的好地方呢? 还是有一个更具说服力的方式,在特定的视图上绘制菜单,而不会大量复制菜单相关的代码?

菜单本身将显示在大多数屏幕上,所以我需要select性地启用它。 根据用户当前所在的视图/屏幕,它也会有所不同。

任何可怕的想法?

你可以创build自己的animation和所有的东西,或者你可以检查这个库

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() } } 

在这里输入图像说明

你可以使用视图控制器遏制。 该菜单可以是其自己的视图控制器,其视图透明地放置在内容视图控制器的顶部。

例如,可以通过将两个容器视图拖放到一个香草视图控制器中来设置故事板。

这个伟大的图书馆还有另一种select:

https://github.com/yoavlt/LiquidFloatingActionButton

你只需要在你的ViewController中实现委托和数据源:

 let floatingActionButton = LiquidFloatingActionButton(frame: floatingFrame) floatingActionButton.dataSource = self floatingActionButton.delegate = self 

在这里输入图像说明