How I can pinch zoom UIImage without using UIImage

2019-09-17 15:00发布

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

2条回答
贪生不怕死
2楼-- · 2019-09-17 15:27

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.

查看更多
Fickle 薄情
3楼-- · 2019-09-17 15:30

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
查看更多
登录 后发表回答