PinchGesture

  1. 6 years ago

    Joel_Eisenstat

    23 Aug 2017 User since 2016

    Good afternoon,
    I was able to utilize the TapGesture but am having trouble with the PinchGesture.
    Any comments on the code are appreciated.
    PinchGesture1 - Action()
    if ( self.state == GestureRecognizerState.Began) { //initial frame
    ImageView1.refFrame = ImageView1.frame ;
    return ;
    }
    if (self.state == GestureRecognizerState.Ended) { //final frame
    var newframe = ImageView1.refFrame.copy();
    newframe.orgin.x += self.locationInView(Window1).x ; //as per example ?
    newframe.orgin.y += self.locationInView(Window1).y ;
    ImageView1.frame = newframe ;
    }
    Thanks,
    Joel

  2. marco

    24 Aug 2017 Administrator User since 2016
    Edited 6 years ago by marco

    Hi @Joel_Eisenstat, you forgot to set the "User interaction" check for ImageView1 (as in the screenshot).
    The code you used was fine for the TapGesture but I think you'd like to have zoom capabilities for the PinchGesture, so your code should look like:

    if ( self.state == GestureRecognizerState.Began) {    //initial frame 
    	ImageView1.refFrame = ImageView1.frame ;
    	return ;
    }
    
    if (self.state == GestureRecognizerState.Ended) {   //final frame
    	var r = ImageView1.refFrame.copy();
    	r.size.width *= self.scale;
    	r.size.height *= self.scale;
    	r.origin.x -= (r.size.width - ImageView1.refFrame.size.width) / 2;
    	r.origin.y -= (r.size.height - ImageView1.refFrame.size.height) / 2;
    	ImageView1.frame = r;
    
    }

    I attached an updated project.

  3. Joel_Eisenstat

    25 Aug 2017 User since 2016

    Hi Marco,
    Thanks for the great example. Aggregate these for for a 'tips and tricks' section.
    Joel

or Sign Up to reply!