【问题标题】:Creating a floating menu in an iOS application在 iOS 应用程序中创建浮动菜单
【发布时间】:2015-08-13 04:07:28
【问题描述】:

希望在 Swift 中为我正在开发的 iOS 应用程序创建一个浮动菜单。沿着小红圈菜单的线条,如下图所示。

我最初的想法是扩展 UIViewController 类并在其中添加相应的绘图/逻辑,但是,该应用程序由一些其他控制器组成,更具体地说是 UITableViewController,它本身扩展了 UIViewController。也许有一个扩展的好地方吗?或者是否有更雄辩的方式在特定视图上绘制菜单,而无需大量重复菜单相关代码?

菜单本身将显示在大多数屏幕上,因此我需要选择性地启用它。它还会根据用户当前所在的视图/屏幕在一定程度上与上下文相关。

有什么好主意吗?

【问题讨论】:

  • 到目前为止你尝试了什么?
  • 嗯,我已经在我早期的应用程序原型中尝试了扩展 UIViewController 方法,该方法适用于简单的单个视图,但后来我遇到了使用 UITableViewControllers、UINavigationControllers 等的问题,因为我不能简单地拥有它们扩展了 UIViewController 而不会失去各自类奠定的基础。
  • 希望答案值得。
  • 顺便说一句,看起来是个不错的 UI 创意!

标签: ios swift menu


【解决方案1】:

你可以创建你自己的动画和所有的东西,或者你可以查看这个库

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

【讨论】:

  • 太棒了,我最终使用这个 pod 的一部分来滚动我自己的菜单,因为它不能完全满足我的需求,但这绝对是一个很好的起点!
  • @r3oath 太好了 :) 继续努力。欢迎随时:)
  • 我怎样才能增加选项图标的高度和宽度,如谷歌加等我试过但它不起作用
【解决方案2】:

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

https://github.com/yoavlt/LiquidFloatingActionButton

您只需在 ViewController 中实现委托和数据源:

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

【讨论】:

    【解决方案3】:

    您可以使用视图控制器遏制。菜单可以是它自己的视图控制器,其视图透明地放置在内容视图控制器之上。

    例如,可以通过将两个容器视图拖出到普通视图控制器中来在情节提要中进行设置。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-05-19
      • 2023-02-12
      • 2016-04-15
      • 2015-05-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多