博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
3D Touch (github下载源码)
阅读量:4217 次
发布时间:2019-05-26

本文共 4112 字,大约阅读时间需要 13 分钟。

3D Touch 是苹果iOS9推出的新特性,同样是iPhone6s6sPlus的一个新功能。之前的苹果设备则不能实现这样的功能。它的出现使app更加便捷化,能够让用户快速的定位到目的页面。

实现3D Touch功能有 动态  和 静态 两种:

动态:

   

//标题一    UIApplicationShortcutItem *item1 = [[UIApplicationShortcutItemalloc]initWithType:@"TianYou.Home"localizedTitle:@"首页"localizedSubtitle:@"副标题一"icon:[UIApplicationShortcutIconiconWithType:UIApplicationShortcutIconTypeHome]userInfo:nil];    //标题二    UIApplicationShortcutItem *item2 = [[UIApplicationShortcutItemalloc]initWithType:@"TianYou.Found"localizedTitle:@"发现"localizedSubtitle:@"副标题二"icon:[UIApplicationShortcutIconiconWithType:UIApplicationShortcutIconTypeBookmark]userInfo:nil];    //标题三    UIApplicationShortcutItem *item3 = [[UIApplicationShortcutItemalloc]initWithType:@"TianYou.Activity"localizedTitle:@"活动"localizedSubtitle:@"副标题三"icon:[UIApplicationShortcutIconiconWithType:UIApplicationShortcutIconTypeConfirmation]userInfo:nil];    //标题四    UIApplicationShortcutItem *item4 = [[UIApplicationShortcutItemalloc]initWithType:@"TianYou.My"localizedTitle:@"我的"localizedSubtitle:@"副标题四"icon:[UIApplicationShortcutIconiconWithType:UIApplicationShortcutIconTypeLove]userInfo:nil];    // shortcutItems是一个数组    [UIApplicationsharedApplication].shortcutItems =@[item1,item2,item3,item4];

静态:

注意:UIApplicationShortcutItemType和UIApplicationShortcutItemTitle为必填,其它为选填

然后加上判断就能快捷启动了如下:

// iOS9 的 3D Touch 判断- (void)application:(UIApplication *)application performActionForShortcutItem:(UIApplicationShortcutItem *)shortcutItem completionHandler:(void(^)(BOOL succeeded))completionHandler{    if ([[[UIDevicecurrentDevice]systemVersion]floatValue] >=9.0 &&self.window.traitCollection.forceTouchCapability == UIForceTouchCapabilityAvailable)    {        NSLog(@"你的手机支持3D Touch!");        TianYouNetCountManager * NetCountManager = [TianYouNetCountManagersharedNetCountManager];        NetCountManager.applicationShortcutItemTitle = shortcutItem.type;        //首页        if([shortcutItem.typeisEqualToString:@"TianYou.Home"])        {            [[NSNotificationCenterdefaultCenter]postNotificationName:@"TianYou.Home"object:niluserInfo:nil];        }        //发现        if([shortcutItem.typeisEqualToString:@"TianYou.Found"])        {            [[NSNotificationCenterdefaultCenter]postNotificationName:@"TianYou.Found"object:niluserInfo:nil];        }        //活动        if([shortcutItem.typeisEqualToString:@"TianYou.Activity"])        {            [[NSNotificationCenterdefaultCenter]postNotificationName:@"TianYou.Activity"object:niluserInfo:nil];        }        //我的        if([shortcutItem.typeisEqualToString:@"TianYou.My"])        {            [[NSNotificationCenterdefaultCenter]postNotificationName:@"TianYou.My"object:niluserInfo:nil];        }    }    else    {        NSLog(@"你的手机暂不支持3D Touch!");    }}

⬆️以上代码我都写在AppDelegate.m文件中,仅供参考和理解。

附上实际效果图如下:

UIApplicationShortcutIconType是系统给的一个枚举类型,里面有多种图标样式供我们选择:

  • UIApplicationShortcutIconTypeShare ===>分享

  • UIApplicationShortcutIconTypeUpdate ===> 更新

  • UIApplicationShortcutIconTypeTime ===>时间

  • UIApplicationShortcutIconTypeAdd ===>添加

  • UIApplicationShortcutIconTypeAlarm ===> 闹钟

  • UIApplicationShortcutIconTypeAudio ===> 声音

  • UIApplicationShortcutIconTypeBookmark ===> 书签

  • UIApplicationShortcutIconTypeCapturePhoto ===> 图片

  • UIApplicationShortcutIconTypeCaptureVideo ===> 视频

  • UIApplicationShortcutIconTypeCloud ===> 云端

  • UIApplicationShortcutIconTypeCompose ===> 备忘

  • UIApplicationShortcutIconTypeConfirmation ===> 确认

  • UIApplicationShortcutIconTypeContact ===> 联系人

  • UIApplicationShortcutIconTypeDate ===> 日期

  • UIApplicationShortcutIconTypeFavorite ===> 收藏

  • UIApplicationShortcutIconTypeHome ===> 首页

  • UIApplicationShortcutIconTypeInvitation ===> 下载

  • UIApplicationShortcutIconTypeLocation ===> 导航

  • UIApplicationShortcutIconTypeLove ===> 关注

  • UIApplicationShortcutIconTypeMail ===> 邮件

  • UIApplicationShortcutIconTypeMarkLocation ===> 标记位置

  • UIApplicationShortcutIconTypeMessage ===> 信息

  • UIApplicationShortcutIconTypePause ===> 暂停

  • UIApplicationShortcutIconTypePlay ===> 播放

  • UIApplicationShortcutIconTypeProhibit ===> 禁止

  • UIApplicationShortcutIconTypeSearch ===> 搜索

  • UIApplicationShortcutIconTypeTask ===> 任务

  • UIApplicationShortcutIconTypeShuffle ===> 交流

  • UIApplicationShortcutIconTypeTaskCompleted ===> 完成

项目链接: https://github.com/TianYou899/3D-Touch

你可能感兴趣的文章
lua math.ceil math.ceil
查看>>
cocos2dx CCNode计算node的大小
查看>>
cocos2dx 布局记录(1)
查看>>
lua 多行注释和取消多行注释
查看>>
缩放系数计算
查看>>
cocos2dx --- 按钮点击居中放大
查看>>
cocos2dx menu位置计算
查看>>
cocos2dx资源加载机制(同步/异步)
查看>>
cocos2dx C++调用java -- 字符串传递
查看>>
git学习网站
查看>>
JavaScript 学习网站
查看>>
cocos2dx java调用c++ -- 字符串传递
查看>>
CCScaleTo与CCScaleBy比较
查看>>
cocos2dx CCObject引用计数,内存释放分析(1)
查看>>
cocos2dx2.X 编译时,传递编译选项
查看>>
ccCArray.cpp 文件
查看>>
cocos2dx 屏幕大小
查看>>
libgdx: 2D Particle Editor工具使用
查看>>
eclipse 给jar库添加源码
查看>>
3.0正式版环境搭建(4)-- 运行(3)创建的工程
查看>>