简体   繁体   中英

Pinch and Zoom UIImage

I would like to edit an UIImage like contacts -> edit profile -> edit image does. I am getting the images originally from the UIImagePickerController and then saving locally. Is this possible using the UIImagePickerController or do I need to go another route? 在此输入图像描述

You can zoom imageview like,

self.scrollView.minimumZoomScale = 0.2;
self.scrollView.maximumZoomScale = 5.0;
self.scrollView.delegate = self;

and you need to implement scrollview delegate like,

 -(UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView
{
    return self.imgView;
}

You should have scrollview contains imageview in your interface builder or say your view controller.

You need to confirm UIScrollViewDelegate !

then you can zoom in or zoom out in your image view!

Swift :

    self.scrollView.minimumZoomScale = 0.2
    self.scrollView.maximumZoomScale = 5.0
    self.scrollView.delegate = self

and

  func viewForZooming(in scrollView: UIScrollView) -> UIView? {

    return self.imgView
   }

You can use this library which saves lot of time.

https://github.com/ruslanskorb/RSKImageCropper

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM