3DTouch

 1 import UIKit
 2 
 3 @UIApplicationMain
 4 class AppDelegate: UIResponder, UIApplicationDelegate {
 5     
 6     var window: UIWindow?
 7     
 8     
 9     func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
10         
11         set3DTouch(application: application)
12         
13         return true
14     }
15     
16     // MARK: - 3DTouch设置
17     private func set3DTouch(application:UIApplication){
18         
19         /*
20          UIApplicationShortcutIcon(templateImageName: String) // 自定义图标,需和系统图标样式一致
21          UIApplicationShortcutIcon(type: UIApplicationShortcutIconType) // 系统图标
22          */
23         
24         let share = UIApplicationShortcutIcon(type: .share)
25         let shareItem = UIApplicationShortcutItem(type: "share", localizedTitle: "分享", localizedSubtitle: nil, icon: share, userInfo: nil)
26         
27         let love = UIApplicationShortcutIcon(type: .love)
28         let loveItem = UIApplicationShortcutItem(type: "love", localizedTitle: "", localizedSubtitle: nil, icon: love, userInfo: nil)
29         
30         let home = UIApplicationShortcutIcon(type: .home)
31         let homeItem = UIApplicationShortcutItem(type: "home", localizedTitle: "", localizedSubtitle: "home", icon: home, userInfo: nil)
32         
33         let cloud = UIApplicationShortcutIcon(type: .cloud)
34         let cloudItem = UIApplicationShortcutItem(type: "cloud", localizedTitle: "", localizedSubtitle: "cloud", icon: cloud, userInfo: nil)
35         
36         application.shortcutItems = [cloudItem,shareItem,loveItem,homeItem]
37     }
38     
39     // MARK: - 3DTouch点击对应的行为
40     func application(_ application: UIApplication, performActionFor shortcutItem: UIApplicationShortcutItem, completionHandler: @escaping (Bool) -> Void) {
41         if shortcutItem.type == "share"{
42             print("share")
43         } else if shortcutItem.type == "love"{
44             print("love")
45         } else if shortcutItem.type == "home"{
46             print("home")
47         } else if shortcutItem.type == "cloud"{
48             print("cloud")
49         } else{
50             print("other")
51         }
52     }
53 }
原文地址:https://www.cnblogs.com/panda1024/p/6364692.html