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
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(实例成员)
您需要使用iPhone 6S或将来的技术才能使用此插件的功能,因此您可以在运行时检查用户的设备是否受支持。
返回一个promise ,使用一个布尔值来表示插件是否可用
当用户强制触及网络视图时,您可以收到通知。 当至少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 | (可选)可以用来提供你自己的图标 | 
当按住主图标时,您的应用程序将启动并调用此JS回调。
返回一个Observable,当用户按下主屏幕图标时通知您
启用链接预览。 UIWebView和WKWebView(提供Cordova应用程序的网络浏览功能)不允许iOS9的漂亮的新链接预览功能。
禁用链接预览功能,如果启用。
ThreeDeeTouchQuickAction
| 参数 | 类型 | 详情 | 
|---|---|---|
| type | string | 可以在onHomeIconPressed回调中使用的类型(可选) | 
| title | string | 标题 | 
| subtitle | string | 副标题(可选) | 
| iconType | string | 图标类型。 不区分大小写(可选) | 
| iconTemplate | string | 图标模板(可选) | 
ThreeDeeTouchForceTouch
| 参数 | 类型 | 详情 | 
|---|---|---|
| force | number | 触摸力 | 
| timestamp | number | 行为时间 | 
| x | number | 行为X坐标 | 
| y | number | 行为Y坐标 | 












网友评论