Pinch gesture still not working


#1

I was trying to recognize pinch gesture in my ionic app. I used a simple directive I found here

import {Directive, ElementRef, Input, OnInit, OnDestroy} from '@angular/core';
import {Gesture} from 'ionic-angular/gestures/gesture';


@Directive({
  selector: '[longPress]' // Attribute selector
})
export class PressDirective implements OnInit, OnDestroy {
  el: HTMLElement;
  pressGesture: Gesture;
  pinchGesture: Gesture;

  constructor(el: ElementRef) {
    this.el = el.nativeElement;
  }

  ngOnInit() {
    this.pressGesture = new Gesture(this.el);
    this.pressGesture.listen();
    this.pressGesture.on('press', e => {
      console.log('pressed!!');
    });

    this.pinchGesture = new Gesture(this.el);
    this.pinchGesture.listen();
    this.pinchGesture.on('pinchin',e => {
      console.log('pinched');
    })
  }

  ngOnDestroy() {
    this.pressGesture.destroy();
  }
}

The press gesture is working without any problem but the pinch is not working. In place of ‘pinchin’ I tried every pinch gesture but still its not working.


#2

Why use this old blogpost with old code instead of reading the documentation and use the build-in pinch handler?

“Basic gestures can be accessed from HTML by binding to tap, press, pan, swipe, rotate, and pinch events.” Documented over here.


#3

it isn’t his fault . any developer try google to find a solution for his problem and all google first results are for Ionic ver 1 often! and ionic official documents are not full and complete just pointed to topics. maybe it’s a good idea for ionic development team to select special code names for any new ionic framework in future or work better on their sites SEO.


#4

Or just use the search function and check the version of your liking, enter your searchquery and hit search.


#5

I have tried basic gestures right now, all other events are working except pinch!

<ion-scroll id="StoryText" class="StoryText" direction="xy" scrollbar-x="false" scrollbar-y="false"
      zooming="true" [style.font-size.px]="this.currentfontsize" (pinch)="swipeEvent($event)">

where is my mistake !? i am testing on device (with remote debugging)


#6

hmmm… maybe because it’s on a ion-scroll? Did you test it out on an ion-card or something like that?


#7

I’ve just added an additional answer to the thread you refer to. To not add that same answer here as well, it might also help you too: Pinch Gesture is not working.