How I can pinch zoom UIImage without using UIImage

2019-09-17 14:36发布

问题:

I have UIImage and I want to scale it without setting it into UIImageView. How I can do that ?

回答1:

As @rckoenes mentioned, UIImage is simply an image object, it does not handle display, which is precisely what UIImageView is for.

For pinch zooming an image, the easiest way is to add a UIImageView as a subview to a UIScrollView.



回答2:

If what you wanted was to change the size of your UIImage, I answered this here: set size of an image programatically

Simply do this:

// Given a UIImage image and a CGSize newSize:

UIGraphicsBeginImageContextWithOptions(newSize, NO, 0.0);
[image drawInRect:CGRectMake(0, 0, newSize.width, newSize.height)];
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

// Your scaled image is now in newImage