IOS 3D Touch

直接代码
Demo :

http://pan.baidu.com/disk/home#list/path=%2FIOS%E5%BC%80%E5%8F%91Demo
如下 :
AppDelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.

//设置图标长按时,弹出的样式.
//iconWithType:图标的类型
UIApplicationShortcutIcon *icon0 =
[UIApplicationShortcutIcon iconWithType:UIApplicationShortcutIconTypeCompose];
UIApplicationShortcutIcon *icon1 =
[UIApplicationShortcutIcon iconWithType:UIApplicationShortcutIconTypePlay];
//创建第一个标题
UIApplicationShortcutItem *item0 = [[UIApplicationShortcutItem alloc] initWithType:@"tpye0"
                                                                    localizedTitle:@"分享"
                                                                 localizedSubtitle:@"精彩瞬间"
                                                                              icon:icon0
                                                                          userInfo:@{@"info": @"我是要传入的信息"}];
//创建第二个标题
UIApplicationShortcutItem *item1 = [[UIApplicationShortcutItem alloc] initWithType:@"tpye1"
                                                                    localizedTitle:@"定位"
                                                                 localizedSubtitle:@"MapView"
                                                                              icon:icon1
                                                                          userInfo:@{@"info": @"我是要传入的信息"}];

//设置shortcutItems
application.shortcutItems = @[item0,item1];
return YES;
}
//当点击AppIcon弹窗口,点击标题时调用
//shortcutItem点击的是哪一个Item
- (void)application:(UIApplication *)application performActionForShortcutItem:(nonnull UIApplicationShortcutItem *)shortcutItem completionHandler:(nonnull void (^)(BOOL))completionHandler
{
//通过判断initWithType标题的类型,执行相应的操作
if ([shortcutItem.type isEqualToString:@"tpye0"]) {
    UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"温馨提示" message:@"分享" delegate:nil cancelButtonTitle:@"确认" otherButtonTitles:@"取消", nil];
    [alertView show];
} else {
    UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"温馨提示" message:@"定位" delegate:nil cancelButtonTitle:@"确认" otherButtonTitles:@"取消", nil];
    [alertView show];
}
}

你可能感兴趣的:(IOS 3D Touch)