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(支持平臺(tái))
iOS
Usage(用法)
更多用法請(qǐng)?jiān)敿?xì)參考原始插件備用版。 這里的使用示例可能不足。
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(實(shí)例成員)
您需要使用iPhone 6S或?qū)?lái)的技術(shù)才能使用此插件的功能,因此您可以在運(yùn)行時(shí)檢查用戶(hù)的設(shè)備是否受支持。
返回一個(gè)promise ,使用一個(gè)布爾值來(lái)表示插件是否可用
當(dāng)用戶(hù)強(qiáng)制觸及網(wǎng)絡(luò)視圖時(shí),您可以收到通知。 當(dāng)至少75%的最大力量施加到屏幕時(shí),該插件定義了力觸摸。 您的應(yīng)用程序?qū)⑹盏絰和y坐標(biāo),因此您必須找出哪個(gè)UI元素被觸摸。
返回發(fā)送ThreeDeeTouchForceTouch的observable對(duì)象
configureQuickActions(type, title, subtitle, iconType, iconTemplate)
設(shè)置3D-Touch操作,使用以下對(duì)象的數(shù)組
| 參數(shù) | 類(lèi)型 | 詳情 |
|---|---|---|
| type | string | (可選)可以在HomeIconPressed回調(diào)上使用的類(lèi)型 |
| title | string | 執(zhí)行動(dòng)作的標(biāo)題 |
| subtitle | string | (可選)執(zhí)行動(dòng)作的副標(biāo)題 |
| 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 | (可選)可以用來(lái)提供你自己的圖標(biāo) |
當(dāng)按住主圖標(biāo)時(shí),您的應(yīng)用程序?qū)?dòng)并調(diào)用此JS回調(diào)。
返回一個(gè)Observable,當(dāng)用戶(hù)按下主屏幕圖標(biāo)時(shí)通知您
啟用鏈接預(yù)覽。 UIWebView和WKWebView(提供Cordova應(yīng)用程序的網(wǎng)絡(luò)瀏覽功能)不允許iOS9的漂亮的新鏈接預(yù)覽功能。
禁用鏈接預(yù)覽功能,如果啟用。
ThreeDeeTouchQuickAction
| 參數(shù) | 類(lèi)型 | 詳情 |
|---|---|---|
| type | string | 可以在onHomeIconPressed回調(diào)中使用的類(lèi)型(可選) |
| title | string | 標(biāo)題 |
| subtitle | string | 副標(biāo)題(可選) |
| iconType | string | 圖標(biāo)類(lèi)型。 不區(qū)分大小寫(xiě)(可選) |
| iconTemplate | string | 圖標(biāo)模板(可選) |
ThreeDeeTouchForceTouch
| 參數(shù) | 類(lèi)型 | 詳情 |
|---|---|---|
| force | number | 觸摸力 |
| timestamp | number | 行為時(shí)間 |
| x | number | 行為X坐標(biāo) |
| y | number | 行為Y坐標(biāo) |