iOS 3DTouch功能

iOS 3DTouch功能

介绍

  • 3D Touch是一种立体触控技术,被苹果称为新一代多点触控技术,是在Apple Watch上采用的Force Touch,屏幕可感应不同的感压力度触控。3D Touch,苹果iPhone 6s的新功能。有Peek和Pop两种新手势。3D-Touch技术,相对于多点触摸在平面二维空间的操作,3D-Touch技术增加了对力度和手指面积的感知,可以通过长按快速预览/查看你想要的短信/图片/超链接等内容,Peek和Pop手势的响应时间可迅捷到10ms和15ms。

  • iPhone 6s之后的机型全都匹配了 3dtouch功能

主要应用

  • 主屏交互(Home Screen Interaction) - 适合跳转到简单界面
  • 预览和跳转(Peek and Pop)
  • LivePhoto

更改plist 实现

UIApplicationShortcutItems:数组中的元素就是我们的那些快捷选项标签。
UIApplicationShortcutItemTitle:标签标题(必填)
UIApplicationShortcutItemType:标签的唯一标识 (必填)
UIApplicationShortcutItemIconType:使用系统图标的类型,如搜索、定位、home等(可选)
UIApplicationShortcutItemIcon File:使用项目中的图片作为标签图标 (可选)
UIApplicationShortcutItemSubtitle:标签副标题 (可选)
UIApplicationShortcutItemUserInfo:字典信息,如传值使用 (可选)
	<key>UIApplicationShortcutItems</key>
	<array>
		<dict>
			<key>UIApplicationShortcutItemTitle</key>
			<string>测试一下1</string>
			<key>UIApplicationShortcutItemType</key>
			<string>test1</string>
		</dict>
        <dict>
            <key>UIApplicationShortcutItemTitle</key>
            <string>测试一下2</string>
            <key>UIApplicationShortcutItemType</key>
            <string>test2</string>
        </dict>
	</array>

主屏交互代码实现

   UIApplicationShortcutIconTypeCompose,
    UIApplicationShortcutIconTypePlay,
    UIApplicationShortcutIconTypePause,
    UIApplicationShortcutIconTypeAdd,
    UIApplicationShortcutIconTypeLocation,
    UIApplicationShortcutIconTypeSearch,
    UIApplicationShortcutIconTypeShare
  • appdelegate 中添加
- (void)setup3DTouch{
    // 判断是否支持3DTouch
    
    if ([[UIApplication sharedApplication] respondsToSelector:@selector(shortcutItems)]) {
        UIApplicationShortcutIcon *icon1 = [UIApplicationShortcutIcon iconWithType:UIApplicationShortcutIconTypeAdd];
        UIApplicationShortcutIcon *icon2 = [UIApplicationShortcutIcon iconWithType:UIApplicationShortcutIconTypeAdd];
        UIMutableApplicationShortcutItem *item1 = [[UIMutableApplicationShortcutItem alloc] initWithType:@"addCar" localizedTitle:@"新增车辆盘查" localizedSubtitle:nil icon:icon1 userInfo:nil];
        UIMutableApplicationShortcutItem *item2 = [[UIMutableApplicationShortcutItem alloc] initWithType:@"addPerson" localizedTitle:@"新增人员盘查" localizedSubtitle:nil icon:icon2 userInfo:nil];
        [[UIApplication sharedApplication] setShortcutItems:@[item1,item2]];
    }
}

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    [self setup3DTouch];
    return YES;
}



  • 实现代理方法
#pragma mark - 3DTouch action

- (void)application:(UIApplication *)application performActionForShortcutItem:(UIApplicationShortcutItem *)shortcutItem completionHandler:(void (^)(BOOL))completionHandler {
    
    NSString *type = shortcutItem.type;
    NSLog(@"shortcutItem:%@",type);

    if ([type isEqualToString:@"addCar"]) {
    
        UINavigationController *rootViewController = (UINavigationController*)[UIApplication sharedApplication].keyWindow.rootViewController;
        NSArray *viewControllers = rootViewController.viewControllers;
        MainViewController *navi = viewControllers[0];
        Test1ViewController *vc = [[Test1ViewController alloc] init];
        [navi.navigationController pushViewController:vc animated:YES];
        
    }else {
        UINavigationController *rootViewController = (UINavigationController*)[UIApplication sharedApplication].keyWindow.rootViewController;
        NSArray *viewControllers = rootViewController.viewControllers;
        MainViewController *navi = viewControllers[0];
        Test2ViewController *vc = [[Test2ViewController alloc] init];
        [navi.navigationController pushViewController:vc animated:YES];
    }
}

参考

posted @ 2022-02-14 09:54  struggle_time  阅读(656)  评论(0编辑  收藏  举报