3D触摸(3D Touch)

3D Touch

Repo(备用): https://github.com/EddyVerbruggen/cordova-plugin-3dtouch

Installation(安装)

1.安装Cordoba和Ionic原生插件:

$ ionic cordova plugin add cordova-plugin-3dtouch
$ npm install --save @ionic-native/three-dee-touch

2.添加插件 app's module

Supported platforms(支持平台)

iOS

Usage(用法)

更多用法请详细参考原始插件备用版。 这里的使用示例可能不足。

import { ThreeDeeTouch, ThreeDeeTouchQuickAction, ThreeDeeTouchForceTouch } from '@ionic-native/three-dee-touch';

constructor(private threeDeeTouch: ThreeDeeTouch) { }

...

this.threeDeeTouch.isAvailable().then(isAvailable => console.log('3D Touch available? ' + isAvailable));

this.threeDeeTouch.watchForceTouches()
  .subscribe(
    (data: ThreeDeeTouchForceTouch) => {
      console.log('Force touch %' + data.force);
      console.log('Force touch timestamp: ' + data.timestamp);
      console.log('Force touch x: ' + data.x);
      console.log('Force touch y: ' + data.y);
    }
  );


let actions: Array<ThreeDeeTouchQuickAction> = [
  {
    type: 'checkin',
    title: 'Check in',
    subtitle: 'Quickly check in',
    iconType: 'Compose'
  },
  {
    type: 'share',
    title: 'Share',
    subtitle: 'Share like you care',
    iconType: 'Share'
  },
  {
    type: 'search',
    title: 'Search',
    iconType: 'Search'
  },
  {
    title: 'Show favorites',
    iconTemplate: 'HeartTemplate'
  }
];

this.threeDeeTouch.configureQuickActions(actions);

this.threeDeeTouch.onHomeIconPressed().subscribe(
 (payload) => {
   // returns an object that is the button you presed
   console.log('Pressed the ${payload.title} button')
   console.log(payload.type)

 }
)

Instance Members(实例成员)

isAvailable()

您需要使用iPhone 6S或将来的技术才能使用此插件的功能,因此您可以在运行时检查用户的设备是否受支持。
返回一个promise ,使用一个布尔值来表示插件是否可用

watchForceTouches()

当用户强制触及网络视图时,您可以收到通知。 当至少75%的最大力量施加到屏幕时,该插件定义了力触摸。 您的应用程序将收到x和y坐标,因此您必须找出哪个UI元素被触摸。
返回发送ThreeDeeTouchForceTouch的observable对象

configureQuickActions(type, title, subtitle, iconType, iconTemplate)

设置3D-Touch操作,使用以下对象的数组

参数 类型 详情
type string (可选)可以在HomeIconPressed回调上使用的类型
title string 执行动作的标题
subtitle string (可选)执行动作的副标题
iconType string (可选) 选择 Prohibit, Contact, Home, MarkLocation, Favorite, Love, Cloud, Invitation, Confirmation, Mail, Message, Date, Time, CapturePhoto, CaptureVideo, Task, TaskCompleted, Alarm, Bookmark, Shuffle, Audio, Update
iconTemplate string (可选)可以用来提供你自己的图标

onHomeIconPressed()

当按住主图标时,您的应用程序将启动并调用此JS回调。
返回一个Observable,当用户按下主屏幕图标时通知您

enableLinkPreview()

启用链接预览。 UIWebView和WKWebView(提供Cordova应用程序的网络浏览功能)不允许iOS9的漂亮的新链接预览功能。

disableLinkPreview()

禁用链接预览功能,如果启用。

ThreeDeeTouchQuickAction

参数 类型 详情
type string 可以在onHomeIconPressed回调中使用的类型(可选)
title string 标题
subtitle string 副标题(可选)
iconType string 图标类型。 不区分大小写(可选)
iconTemplate string 图标模板(可选)

ThreeDeeTouchForceTouch

参数 类型 详情
force number 触摸力
timestamp number 行为时间
x number 行为X坐标
y number 行为Y坐标
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 135,026评论 19 139
  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 173,705评论 25 709
  • 我从去年开始使用 RxJava ,到现在一年多了。今年加入了 Flipboard 后,看到 Flipboard 的...
    Jason_andy阅读 5,602评论 7 62
  • 发现 关注 消息 iOS 第三方库、插件、知名博客总结 作者大灰狼的小绵羊哥哥关注 2017.06.26 09:4...
    肇东周阅读 12,261评论 4 61
  • 看了那么多的别人的文字,可是写不出自己的文章。 不是不想写,是写不出。 不是没有观点,是没有拿得出手的观点。 不是...
    言不相喻阅读 221评论 0 0