★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★
➤微信公众号:山青咏芝(shanqingyongzhi)
➤博客园地址:山青咏芝(https://www.cnblogs.com/strengthen/)
➤GitHub地址:https://github.com/strengthen/LeetCode
➤原文地址:http://www.javashuo.com/article/p-erhplump-gu.html
➤若是连接不是山青咏芝的博客园地址,则多是爬取做者的文章。
➤原文已修改更新!强烈建议点击原文地址阅读!支持做者!支持原创!
★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★html
目录:[Swift]通天遁地Swiftgit
本文将演示3DTouch三维触摸手势的使用。github
双卡双待的iPhone XR中,苹果取消了3DTouch功能。swift
在项目导航区,打开应用程序的代理文件【AppDelegate.swift】api
当三维触摸手势被触发时,将在应用程序的图标位置显示一个菜单列表,数组
如今从建立这个菜单列表开始。微信
1 import UIKit 2 3 @UIApplicationMain 4 class AppDelegate: UIResponder, UIApplicationDelegate 5 { 6 var window: UIWindow? 7 8 func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool 9 { 10 // Override point for customization after application launch. 11 12 //初始化一个应用程序快捷图标, 13 //并设置图标的类型为添加。 14 let addEventIcon = UIApplicationShortcutIcon(type: .add) 15 //初始化另外一个应用程序快捷图标, 16 //并设置图标的类型为自定义图片。 17 let unlockEventIcon = UIApplicationShortcutIcon(templateImageName: "unlockEvent") 18 //初始化另外一个应用程序快捷图标, 19 //并设置图标的类型为自定义图片。 20 let listEventIcon = UIApplicationShortcutIcon(templateImageName: "listEvent") 21 22 //建立菜单列表中的快捷条目,并设置相关参数。 23 let addEvent = UIApplicationShortcutItem(type: "com.coolketang.addMember", //条目的类型 24 localizedTitle: "Add", //本地化标题 25 localizedSubtitle: "Add Member",//子标题 26 icon: addEventIcon, //图标 27 userInfo: nil)//用户数据 28 29 //建立菜单列表中的快捷条目,并设置相关参数。 30 let unlockEvent = UIApplicationShortcutItem(type: "com.coolketang.unlockMember", //条目的类型 31 localizedTitle: "Unlock",//本地化标题 32 localizedSubtitle: "Unlock Member",//子标题 33 icon: unlockEventIcon, //图标 34 userInfo: nil)//用户数据 35 36 //建立菜单列表中的快捷条目,并设置相关参数。 37 let listEvent = UIApplicationShortcutItem(type: "com.coolketang.memberList", //条目的类型 38 localizedTitle: "List", //本地化标题 39 localizedSubtitle: "Members List",//子标题 40 icon: listEventIcon,//图标 41 userInfo: nil)//用户数据 42 43 //将三个快捷条目添加到数组中 44 let shortCutItems = [addEvent, unlockEvent, listEvent] 45 //而后设置应用程序对象的快捷列表,在快捷列表中包含三个快捷条目 46 application.shortcutItems = shortCutItems; 47 48 return true 49 } 50 51 //添加一个方法,用来响应快捷条目被点击时的事件。 52 func application(_ application: UIApplication, performActionFor shortcutItem: UIApplicationShortcutItem, completionHandler: @escaping (Bool) -> Void) { 53 //根据返回的快捷条目的类型,判断用户须要使用哪一个功能。 54 55 //当用户点击第一个条目时 56 if shortcutItem.type == "com.coolketang.addMember" 57 { 58 //在控制台输出对应的日志信息 59 print("Navigate to page for adding memeber.") 60 } 61 //当用户点击第二个条目时 62 else if shortcutItem.type == "com.coolketang.unlockMember" 63 { 64 //在控制台输出对应的日志信息 65 print("Navigate to page for unlocking memeber.") 66 } 67 //当用户点击第三个条目时 68 else if shortcutItem.type == "com.coolketang.memberList" 69 { 70 //在控制台输出对应的日志信息 71 print("Navigate to list of memebers.") 72 } 73 } 74 75 func applicationWillResignActive(_ application: UIApplication) { 76 // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 77 // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. 78 } 79 80 func applicationDidEnterBackground(_ application: UIApplication) { 81 // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 82 // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 83 } 84 85 func applicationWillEnterForeground(_ application: UIApplication) { 86 // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background. 87 } 88 89 func applicationDidBecomeActive(_ application: UIApplication) { 90 // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 91 } 92 93 func applicationWillTerminate(_ application: UIApplication) { 94 // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 95 } 96 }
切换到真机环境,进行三维触摸手势的测试。app
按下【Command】+【Shif】+【H】返回系统界面。ide
稍微用力并长按应用程序的快捷图标,以打开快捷条目列表。post
在打开的快捷条目列表中,左侧时条目的图标,右侧是条目的标题。
点击一个条目,将返回应用程序,并在控制台输出相应的内容。