美文网首页
3Dtouch方法

3Dtouch方法

作者: 苏小贱 | 来源:发表于2015-11-10 15:21 被阅读250次

    @UIApplicationMain

    classAppDelegate:UIResponder,UIApplicationDelegate{

    varwindow:UIWindow?

    funcapplication(application:UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject:AnyObject]?) ->Bool{

    // Override point for customization after application launch.

    //添加icon 3d Touch

    letfirstItemIcon:UIApplicationShortcutIcon=UIApplicationShortcutIcon(type: .Share)

    letfirstItem =UIMutableApplicationShortcutItem(type:"1", localizedTitle:"分享", localizedSubtitle:nil, icon: firstItemIcon, userInfo:nil)

    letfirstItemIcon1:UIApplicationShortcutIcon=UIApplicationShortcutIcon(type: .Compose)

    letfirstItem1 =UIMutableApplicationShortcutItem(type:"2", localizedTitle:"编辑", localizedSubtitle:nil, icon: firstItemIcon1, userInfo:nil)

    application.shortcutItems= [firstItem,firstItem1]

    returntrue

    }

    /**

    3D Touch跳转

    - parameter application:application

    - parameter shortcutItem:item

    - parameter completionHandler: handler

    */

    funcapplication(application:UIApplication, performActionForShortcutItem shortcutItem:UIApplicationShortcutItem, completionHandler: (Bool) ->Void) {

    lethandledShortCutItem =handleShortCutItem(shortcutItem)

    completionHandler(handledShortCutItem)

    }

    funchandleShortCutItem(shortcutItem:UIApplicationShortcutItem) ->Bool{

    varhandled =false

    ifshortcutItem.type=="1"{//分享

    letrootNavigationViewController=window!.rootViewControlleras?UINavigationController

    letrootViewController = rootNavigationViewController?.viewControllers.firstasUIViewController?

    rootNavigationViewController?.popToRootViewControllerAnimated(false)

    rootViewController?.performSegueWithIdentifier("toShare", sender:nil)

    handled =true

    }

    ifshortcutItem.type=="2"{//编辑

    letrootNavigationViewController =window!.rootViewControlleras?UINavigationController

    letrootViewController = rootNavigationViewController?.viewControllers.firstasUIViewController?

    rootNavigationViewController?.popToRootViewControllerAnimated(false)

    rootViewController?.performSegueWithIdentifier("toCompose", sender:nil)

    handled =true

    }

    returnhandled

    }

    https://github.com/itjhDev/itjh_3DTouch

    相关文章

      网友评论

          本文标题:3Dtouch方法

          本文链接:https://www.haomeiwen.com/subject/xirhhttx.html