4

是否有 API 可以在应用程序内显示强制触摸的快速操作菜单?当您向上滑动查看视图时,我只看到用于显示快速操作菜单的 API。但我想做一些类似apple 3D touch page的例子。

这是我想要 在 6s 上实现联系人上的 3D 触摸快速操作菜单

4

2 回答 2

3

可能还有另一种解决方案,但我认为您可以在检测 3D 触摸时显示此自定义视图。你可以从

  • UIViewControllerPreviewingDelegate方法 previewingContext:viewControllerForLocation: ,或者您可以使用forcemaximumPossibleForce属性UITouch来检测屏幕上施加的压力,并在特定压力水平后显示此自定义视图。
于 2016-02-13T13:27:29.333 回答
0

你可以试试我自己的库ActionsList,它与 Apple 的 Quick Actions 菜单具有相同的外观和感觉。

它还没有 3D Touch 支持,但它可以帮助您呈现与提供程序屏幕截图相同的操作列表。

首先,您应该创建列表。

如果您想从 中展示它UIButtonUIBarButtonItem其中UITabBarItem有用于创建列表的内置方法:

// element is UIButton, UIBarButtonItem or UITabBarItem
let list = element.createActionsList()

否则你应该使用ActionsListModel结构:

let list = ActionsListModel(senderView: viewThatInitiatedListPresenting,
                            sourceView: viewToPresentListFrom,
                            delegate: listDelegate)

然后将动作添加到列表中

list.add(action: ActionsListDefaultButtonModel(localizedTitle: "Create Alarm", 
                 image: UIImage(named: "Alarm clock"),
                 action: { action in
                     // You can use action's list property to control it

                     // - To dismiss
                     action.list?.dismiss()

                     // - To update action appearance
                     action.appearance.//anything
                     // Do not forget to reload actions to apply changes
                     action.list?.reloadActions()
          }))

之后,您可以显示列表

list.present()

// Save list or it will be deallocated and not reachable outside of the scope it was created in
self.list = list

在此处输入图像描述

于 2017-12-20T19:57:34.883 回答