Domanda

I have been using UIImagePickerController for my application preview purpose, I have customized and zoom in/out buttons, I didn't used CGAffineTransformScale before, however I have googled and implemented zoom in functionality using CGAffineTransformScale like this...

- (void) zoom_in_clkd
{

        preview_picker.cameraViewTransform = CGAffineTransformScale(preview_picker.cameraViewTransform, 1.0, 1.2499);

}

It seems fine, however I want to implement zoom out functionality, I don't have any idea what should be its sx,sy values in CGAffineTransformScale.

Can anyone please tell a good tutorial or sample code to use CGAffineTransformScale?

È stato utile?

Soluzione 2

I have simulated zoom out functionality in different way, What I have done is I reset to identity(bringing back to original size) and zooming in again to what position I want like this..

      if (cameraTransformX == 2.0) {
            preview_picker.cameraViewTransform = CGAffineTransformIdentity;
            cameraTransformX -= 1.0;
        } else if (cameraTransformX == 3.0) {
            preview_picker.cameraViewTransform = CGAffineTransformIdentity;
            preview_picker.cameraViewTransform = CGAffineTransformScale(preview_picker.cameraViewTransform, 1.0, 1.2499);
            cameraTransformX -= 1.0;
        }  else if (cameraTransformX == 4.0) {
            preview_picker.cameraViewTransform = CGAffineTransformIdentity;
            preview_picker.cameraViewTransform = CGAffineTransformScale(preview_picker.cameraViewTransform, 1.0, 1.2499);
            preview_picker.cameraViewTransform = CGAffineTransformScale(preview_picker.cameraViewTransform, 1.0, 1.2499);
            cameraTransformX -= 1.0;
        }

I know its not a proper way to go back to previous transform, but it will do the tricks. :)

Altri suggerimenti

sx and sy suggests the zoom factor on x and y values respectively.

If you want zoom out the view provide the sx and sy < 1.0

Download the sample code from this link.

My solution was to save initial cameraViewTransform and use that for both zoom in/zoom out. For zoom out you reduce scale, set initially for example at 3. Here is my code:

    // initial cameraViewTransform
    self.initialTransform = self.videoRecorderController.cameraViewTransform;

    // for zoom in
    if(self.zoomIn) {
            // increment scale
            self.scale += 0.5;
            self.videoRecorderController.cameraViewTransform = CGAffineTransformScale(self.initialTransform, self.scale, self.scale);
    }
    // for zoom out
    else {
           self.scale -= 0.5;
           self.videoRecorderController.cameraViewTransform = CGAffineTransformScale(self.initialTransform, self.scale , self.scale);
    }
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top