PinchGesture

  1. 4 weeks ago

    Joel_Eisenstat

    Aug 23 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. 3 weeks ago

    marco

    Aug 24 Administrator User since 2016
    Edited 3 weeks 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

    Aug 25 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!