分享

Ionic2-Gestures tap press pan swipe等手势事件

 飞鹰飞龙飞天 2017-04-07

1

基本的手势可以通过绑定到tap(点击),press(按下),pan(随着手指移动),swipe(随着手指迅速移动),rotate(旋转),pinch(缩放)等事件上的HTML元素来使用,这里只演示前四个。

html

  1. <!--
  2. Generated template for the Gestures page.
  3.  
  4. See http:///docs/v2/components/#navigation for more info on
  5. Ionic pages and navigation.
  6. -->
  7. <!--<ion-header>
  8.  
  9. <ion-navbar>
  10. <ion-title>Gestures</ion-title>
  11. </ion-navbar>
  12.  
  13. </ion-header>-->
  14.  
  15.  
  16. <ion-content padding>
  17.  
  18. <ion-card (tap)="tapEvent($evnet)">
  19. <!--这是通过数据绑定的方式-->
  20. <ion-item> 点击: {{tap}} 次</ion-item>
  21. </ion-card>
  22.  
  23. <ion-card (press)="pressEvent($event)">
  24. <!--这是通过数据绑定的方式-->
  25. <ion-item> 按下:{{press}}次</ion-item>
  26. </ion-card>
  27.  
  28. <ion-card (pan)="panEvent($event)">
  29. <!--这是通过数据绑定的方式-->
  30. <ion-item>手指滑动:{{pan}}次</ion-item>
  31. </ion-card>
  32. <ion-card (swipe)="swipeEvent($evnet)">
  33. <!--这是通过数据绑定的方式-->
  34. <ion-item>手指迅速滑动:{{swipe}}次</ion-item>
  35. </ion-card>
  36.  
  37. </ion-content>

ts

  1. import { Component } from '@angular/core';
  2. import { NavController } from 'ionic-angular';
  3.  
  4. /*
  5. Generated class for the Gestures page.
  6.  
  7. See http:///docs/v2/components/#navigation for more info on
  8. Ionic pages and navigation.
  9. */
  10. @Component({
  11. selector: 'page-gestures',
  12. templateUrl: 'gestures.html'
  13. })
  14. export class GesturesPage {
  15.  
  16. public tap: number = 0;
  17. public press: number = 0;
  18. public pan: number = 0;
  19. public swipe: number = 0;
  20.  
  21. constructor() { }
  22.  
  23.  
  24. /**
  25. * 点击事件处理
  26. */
  27. tapEvent(e) {
  28. // console.log(e);
  29. this.tap++;
  30. }
  31.  
  32. /**
  33. * 按下事件
  34. */
  35. pressEvent(e) {
  36. // console.log(e);
  37. this.press++;
  38. }
  39. /**
  40. * 滑动事件
  41. */
  42. panEvent(e) {
  43. // console.log(e);
  44. this.pan++;
  45. }
  46. /**
  47. * 迅速滑动事件
  48. */
  49. swipeEvent(e) {
  50. // console.log(e);
  51. this.swipe++;
  52. }
  53. ionViewDidLoad() {
  54. console.log('Hello GesturesPage Page');
  55. }
  56.  
  57. }
  58.  

顺子技术栈 , 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明Ionic2-Gestures针对手指触摸屏幕处理

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多