zoukankan      html  css  js  c++  java
  • 3D Touch开发

    一.3d Touch 官方文档介绍

    1.A user can now press your Home screen icon to immediately access functionality provided by your app.

    2.Within your app, a user can now press views to see previews of additional content and gain accelerated access to features.

    第一部分的应用是我们可以通过3D手势,在主屏幕上的应用Icon处,直接进入应用的响应功能模块。这个功能就例如我们上面的日历示例,会在Icon旁边出现一个菜单,点击菜单我们可以进入相应的功能单元。例如点击今日头条app图标便会弹出

    第二部分是对app的一个优化,用户可以通过3D Touch手势在view上来预览一些预加载信息,这样的设计可以使app更加简洁大方,交互性也更强。例如预览短信功能

    二.使用

    针对第一种在 (第一部分的应用是我们可以通过3D手势,在主屏幕上的应用Icon处,直接进入应用的响应功能模块。这个功能就例如我们上面的日历示例,会在Icon旁边出现一个菜单,点击菜单我们可以进入相应的功能单元。)

    在APPDelegate里面的

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {}

    方法里面实现

    UIApplicationShortcutIcon *icon1 = [UIApplicationShortcutIcon iconWithTemplateImageName:@"照片名字1"];

        UIApplicationShortcutIcon *icon2 = [UIApplicationShortcutIcon iconWithTemplateImageName:@"照片名字2"];

        UIMutableApplicationShortcutItem *item1 = [[UIMutableApplicationShortcutItem alloc]initWithType:@"com.test.deep1" localizedTitle:@"名字自己起1" localizedSubtitle:@"Launch 2nd Level" icon:icon1 userInfo:nil];

        UIMutableApplicationShortcutItem *item2 = [[UIMutableApplicationShortcutItem alloc]initWithType:@"com.test.deep2" localizedTitle:@"名字自己起2" localizedSubtitle:@"Launch 2nd Level" icon:icon2 userInfo:nil];

        NSArray *items = @[item1,item2];

        application.shortcutItems = items;

    接着在

    -(void)application:(UIApplication *)application performActionForShortcutItem:(UIApplicationShortcutItem *)shortcutItem completionHandler:(void (^)(BOOL))completionHandler{}

    里面实现点击app角标进来时对应事件的处理

    -(void)application:(UIApplication *)application performActionForShortcutItem:(UIApplicationShortcutItem *)shortcutItem completionHandler:(void (^)(BOOL))completionHandler{

     

    if([shortcutItem.type isEqualToString:@"com.test.deep1"]){

            //自己要做的事情

        }else if ([shortcutItem.type isEqualToString:@"com.test.deep2"]){

    //自己要做的事情
    }

    }

     

    二.在页面里面使用 (用户可以通过3D Touch手势在view上来预览一些预加载信息  流入iPhone7查看信息功能)

    受限

    1.在使用的界面让当前的ViewCotroller遵循UIViewControllerPreviewingDelegate协议

    可在

    - (void)viewWillAppear:(BOOL)animated {}方法里检测手机是否有3D Touch功能

    - (void)viewWillAppear:(BOOL)animated {

    if (self.traitCollection.forceTouchCapability == UIForceTouchCapabilityAvailable) {

           //有3D Touch功能

           

    [self registerForPreviewingWithDelegate:(id)self sourceView:self.view];

           }else{

           //没有3D Touch功能
       }

    }

     

    # pragma mark - 3D Touch Delegate

     //点击进入预览模式: 实现该协议方法

    - (UIViewController *)previewingContext:(id<UIViewControllerPreviewing>)previewingContext viewControllerForLocation:(CGPoint)location {

        

        // check if we're not already displaying a preview controller

        if ([self.presentedViewController isKindOfClass:[PreviewViewController class]]) {

            return nil;

        }

        

        PreviewViewController *previewController = [PreviewViewController new];

        previewController.view.backgroundColor = [UIColor blueColor];

        

        return previewController;

    }

     //继续按压进入:实现该协议

    - (void)previewingContext:(id<UIViewControllerPreviewing>)previewingContext commitViewController:(UIViewController *)viewControllerToCommit {

        

        PreviewViewController *previewController = [PreviewViewController new];

        previewController.view.backgroundColor = [UIColor redColor];

        [self showViewController:previewController sender:self];

    }

    本文借鉴 非常感谢原作者 (他的里面部分有错误 在第一种添加 app 角标选择功能数目那有错误 用本方法没问题  它的方法会导致数目即便是1个多运行几次也会变成四个):http://www.jianshu.com/p/2920d2f74fb4  

     

     

     

     

     

  • 相关阅读:
    SoapUI 使用笔记
    git 使用笔记(二)
    git 使用笔记(一)
    jquery 拓展
    hdu 1024 Max Sum Plus Plus (DP)
    hdu 2602 Bone Collector (01背包)
    hdu 1688 Sightseeing (最短路径)
    hdu 3191 How Many Paths Are There (次短路径数)
    hdu 2722 Here We Go(relians) Again (最短路径)
    hdu 1596 find the safest road (最短路径)
  • 原文地址:https://www.cnblogs.com/qizhuo/p/6383105.html
Copyright © 2011-2022 走看看