3d touch 的使用(一)

 

废话不多说,直接上代码------------------

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions;

方法里面判断,该手机是否是9.0以上,因为3dtouch是9.0以后出的功能

CGFloat currentDeviceVersionFloat = [[[UIDevice currentDevice] systemVersion] floatValue];

//判断版本号,3D Touch是从iOS9.0后开始使用

if (currentDeviceVersionFloat >= 9.0) {

[self addThreeDTouchAction:application]; // 在此方法里面添加3d touch 桌面cell

}

 

- (void)addThreeDTouchAction:(UIApplication *)application{

UIApplicationShortcutIcon *sys = [UIApplicationShortcutIcon iconWithType:<#(UIApplicationShortcutIconType)#>];// 使用此方法,可以调用系统默认的图标

//以下为自定义 

UIApplicationShortcutIcon *iconLottery = [UIApplicationShortcutIcon iconWithTemplateImageName:@"server_lottery"];

/// 3d touch开奖大厅 按钮创建

UIMutableApplicationShortcutItem *itemLottery = [[UIMutableApplicationShortcutItem alloc] initWithType:ThreeDTouchTypeLottery localizedTitle:@"开奖大厅"];// 指定标题

itemLottery.icon = iconLottery; // 指定图标

itemLottery.localizedSubtitle = @"开奖全网最快";// 指定子标题

UIApplicationShortcutIcon *iconGold = [UIApplicationShortcutIcon iconWithTemplateImageName:@"server_gold"];

/// 3d touch开奖大厅 按钮创建

UIMutableApplicationShortcutItem *itemGold = [[UIMutableApplicationShortcutItem alloc] initWithType:ThreeDTouchTypeGold localizedTitle:@"比分赛果"];

itemGold.icon = iconGold;

itemGold.localizedSubtitle = @"比分信息最全";

/// 3d touch开奖大厅 按钮创建

UIApplicationShortcutIcon *iconFriend = [UIApplicationShortcutIcon iconWithTemplateImageName:@"tabbar_find_normal"];

UIMutableApplicationShortcutItem *itemFriend = [[UIMutableApplicationShortcutItem alloc] initWithType:ThreeDTouchTypeFriend localizedTitle:@"身边彩友"];

itemFriend.icon = iconFriend;

itemFriend.localizedSubtitle = @"寻找身边的彩友";

application.shortcutItems = @[itemLottery,itemGold,itemFriend];

}

// 在此方法里面添加你的操作

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

 

注:

// 当项目上线,系统会默认添加分享的功能

// UIApplicationShortcutIconType 的类型校对表

 

posted @ 2017-05-12 11:54  世界仔  阅读(244)  评论(0编辑  收藏  举报