Swift 3DTouch开发 自定义ShortcutItems
3DTouch的分享菜单是上架后系统自动加上的,其他的菜单需要我们自定义。
1.定义菜单项Model
import Foundationenum ShortcutItem {case scancase sendcase receivecase qrcodevar type: String {switch self {case .scan:return "com.app.scan"case .send:return "com.app.send"case .receive:return "com.app.receive"case .qrcode:return "com.app.qrcode"}}var title: String {switch self {case .scan:return "Scan".localizedcase .send:return "Send".localizedcase .receive:return "Receive".localizedcase .qrcode:return "My referral code".localized}}var imageName: String {switch self {case .scan:return "shortcut_scan"case .send:return "shortcut_send"case .receive:return "shortcut_receive"case .qrcode:return "shortcut_qrcode"}}var icon: UIApplicationShortcutIcon {return UIApplicationShortcutIcon(templateImageName: self.imageName)}
}
2.在APPDelegate中设置ShortcutItems
func createShortcutItems() {if #available(iOS 9.1, *) {var itemArray: [UIApplicationShortcutItem] = []for item in [ShortcutItem.scan, ShortcutItem.send, ShortcutItem.receive, ShortcutItem.qrcode] {itemArray.append(UIApplicationShortcutItem(type: item.type, localizedTitle: item.title, localizedSubtitle: nil, icon: item.icon, userInfo: nil))}UIApplication.shared.shortcutItems = itemArray}}
3.实现点击Item事件
func application(_ application: UIApplication, performActionFor shortcutItem: UIApplicationShortcutItem, completionHandler: @escaping (Bool) -> Void) {guard let appDelegate = UIApplication.shared.delegate as? AppDelegate else { return }guard let main = appDelegate.coordinator.coordinators.first as? MainCoordinator else { return }switch shortcutItem.type {case ShortcutItem.scan.type:print("scan")case ShortcutItem.send.type:print("send")case ShortcutItem.receive.type:print("receive")case ShortcutItem.qrcode.type:print("qrcode")default:break}}
Swift 3DTouch开发 自定义ShortcutItems相关推荐
- iOS开发 swift 3dTouch实现 附代码
iOS开发 swift 3dTouch实现 附代码 一.What? 从iphone6s开始,苹果手机加入了3d touch技术,最简单的理解就是可以读取用户的点击屏幕力度大小,根据力度大小给予不同的反 ...
- 从Java/Android到Swift iOS开发:语言与框架对比
今天分享的主题是Java/Android开发人员如何快速上手Swift iOS开发.主要内容如下: WhyFrom Java/Android to Swift Swift语言为什么值得学习? Java ...
- Android Swift iOS开发:语言与框架对比
转载自:http://www.infoq.com/cn/articles/from-android-to-swift-ios?utm_campaign=rightbar_v2&utm_sour ...
- Swift游戏开发实战教程(大学霸内部资料)
Swift游戏开发实战教程(大学霸内部资料) 试读下载地址:http://pan.baidu.com/s/1sj7DvQH 介绍:本教程是国内第一本Swift游戏开发专向资料. 本教程详细讲解记忆配对 ...
- Android开发自定义View
Android中View组件的作用类似于Swing变成中的JPanel,它只是一个空白的矩形区域,View组件中没有任何内容.对于Android应用的其他UI组件来说,它们都继承了View组件,然后在 ...
- 开发自定义JSF组件(4) 保存状态与恢复状态
2019独角兽企业重金招聘Python工程师标准>>> 完整的教材: 开发自定义JSF组件(1) HelloWorld 开发自定义JSF组件(2) 使用Render渲染器 开发自定义 ...
- integer加1_利用Abaqus UEL开发自定义单元1
1. 简介 在Abaqus/Standard模块中,用户可以利用子程序UEL来开发自定义单元,用以实现一些通过Abaqus内置单元无法实现的功能.如果编写恰当,用户自定义单元可以正常使用Abaqus/ ...
- 【Android开发】用户界面设计-开发自定义的View
效果图: Android中,所有的UI界面都是由View类和ViewGroup类及其子类组合而成的.View是所有UI组件的基类(父类),为ViewGroup类是容纳这些UI组件的容器,其本身也是Vi ...
- java自定义菜单跳转页面_微信公众号开发 自定义菜单跳转页面并获取用户信息实例详解...
微信公众号开发 自定义菜单 请先读完本文再进行配置开发 请先前往微信平台开发者文档阅读"网页授权获取用户基本信息"的接口说明 在微信公众账号开发中,往往有定义一个菜单,然后用户点击 ...
最新文章
- 第一讲 IDLE使用
- python之6-3嵌套函数
- 白话详细解读(七)----- Batch Normalization
- VTK:Rendering之HiddenLineRemoval
- 10th blog:Object
- Beaglebone Back学习三(开发环境搭建)
- 《HotSpot实战》读后感
- Flask 中的上下文管理和请求钩子
- (05)System Verilog 数组类型详解
- 冬季海报素材温暖上线,PSD分层设计师最爱
- imu相机标定_【光电视界】多传感器融合标定方法汇总
- vue 显示日期只显示年月_Vue编写可显示周和月模式的日历 Vue自定义日历内容的显示...
- 关于teamviewer不能进行局域网连接的问题
- adprw指令教程_三菱FX5U模拟量,通信,运动控制详解
- npm 及 webpack打包工具
- 【MATLAB】进阶绘图 ( Pie Chart 饼图 | pie 函数 | 三维饼图 | pie3 函数 )
- 浅析 ContentSizeFitter 以及 Horizontal Layout Group 嵌套问题
- Java里面for循环的几种用法
- (转)使用jsonp帮助你知道关注的他或她QQ音乐中搜藏了什么歌曲
- [文章]云计算、大数据和人工智能科普文