3D Touch (github下载源码)
2016-05-13 15:46
190 查看
3D Touch 是苹果iOS9推出的新特性,同样是iPhone6s和6sPlus的一个新功能。之前的苹果设备则不能实现这样的功能。它的出现使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];
静态:
![](https://img-blog.csdn.net/20160513155053964?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center)
注意: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文件中,仅供参考和理解。
附上实际效果图如下:
![](https://img-blog.csdn.net/20160513155618091?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center)
UIApplicationShortcutIconType是系统给的一个枚举类型,里面有多种图标样式供我们选择:
UIApplicationShortcutIconTypeShare ===>
![](https://img-blog.csdn.net/20160315114806874)
UIApplicationShortcutIconTypeUpdate ===>
![](https://img-blog.csdn.net/20160315114828947)
UIApplicationShortcutIconTypeTime ===>
![](https://img-blog.csdn.net/20160315114846281)
UIApplicationShortcutIconTypeAdd ===>
![](https://img-blog.csdn.net/20160315114910525)
UIApplicationShortcutIconTypeAlarm ===>
![](https://img-blog.csdn.net/20160315114700310)
UIApplicationShortcutIconTypeAudio ===>
![](https://img-blog.csdn.net/20160315135149597)
UIApplicationShortcutIconTypeBookmark ===>
![](https://img-blog.csdn.net/20160315135209699)
UIApplicationShortcutIconTypeCapturePhoto ===>
![](https://img-blog.csdn.net/20160315135222434)
UIApplicationShortcutIconTypeCaptureVideo ===>
![](https://img-blog.csdn.net/20160315135235559)
UIApplicationShortcutIconTypeCloud ===>
![](https://img-blog.csdn.net/20160315141319423)
UIApplicationShortcutIconTypeCompose ===>
![](https://img-blog.csdn.net/20160315141308298)
UIApplicationShortcutIconTypeConfirmation ===>
![](https://img-blog.csdn.net/20160315141251739)
UIApplicationShortcutIconTypeContact ===>
![](https://img-blog.csdn.net/20160315141238895)
UIApplicationShortcutIconTypeDate ===>
![](https://img-blog.csdn.net/20160315135939890)
UIApplicationShortcutIconTypeFavorite ===>
![](https://img-blog.csdn.net/20160315135928810)
UIApplicationShortcutIconTypeHome ===>
![](https://img-blog.csdn.net/20160315135916029)
UIApplicationShortcutIconTypeInvitation ===>
![](https://img-blog.csdn.net/20160315135904061)
UIApplicationShortcutIconTypeLocation ===>
![](https://img-blog.csdn.net/20160315135814217)
UIApplicationShortcutIconTypeLove ===>
![](https://img-blog.csdn.net/20160315135801949)
UIApplicationShortcutIconTypeMail ===>
![](https://img-blog.csdn.net/20160315135747605)
UIApplicationShortcutIconTypeMarkLocation ===>
![](https://img-blog.csdn.net/20160315135714354)
UIApplicationShortcutIconTypeMessage ===>
![](https://img-blog.csdn.net/20160315135702514)
UIApplicationShortcutIconTypePause ===>
![](https://img-blog.csdn.net/20160315135651826)
UIApplicationShortcutIconTypePlay ===>
![](https://img-blog.csdn.net/20160315135619588)
UIApplicationShortcutIconTypeProhibit ===>
![](https://img-blog.csdn.net/20160315135602404)
UIApplicationShortcutIconTypeSearch ===>
![](https://img-blog.csdn.net/20160315135550962)
UIApplicationShortcutIconTypeTask ===>
![](https://img-blog.csdn.net/20160315135528982)
UIApplicationShortcutIconTypeShuffle ===>
![](https://img-blog.csdn.net/20160315135513232)
UIApplicationShortcutIconTypeTaskCompleted ===>
![](https://img-blog.csdn.net/20160315135453935)
项目链接: https://github.com/TianYou899/3D-Touch
实现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
相关文章推荐
- iOS 3D Touch
- 关于C# Math 处理奇进偶不进
- springmvc+spring3+hibernate4框架整合完整版
- 文章标题
- Struts2基础学习(七)—值栈和OGNL
- JavaSE入门学习38:Java集合框架之迭代器
- [PHP] 重回基础(date函数和strtotime函数)
- thinkphp 富文本截取字符串
- 【Webhooks】使用Git的Webhooks进行服务器自动部署代码
- Java在eclipse中调用opencv时报错:java.lang.UnsatisfiedLinkError的解决方法
- Asp.net中GridView使用详解
- window下配置SSH连接GitHub、GitHub配置ssh key
- python合并2个字典
- Effective C++ 3e----new & delete(八)条款51:编写new和delete时需固守常规
- spring配置bean作用域
- 腾讯 2015秋招笔试题 编程题2:九宫格填数
- 利用java自带的base64实现加密、解密
- 修改eclipse中settings.xml和默认资源库保存地址
- Java中的抽象类
- Java中数据类型及其之间的转换