当用户捏住屏幕时如何放大/缩小UIImage对象? [英] How to zoom in/out an UIImage object when user pinches screen?

查看:93
本文介绍了当用户捏住屏幕时如何放大/缩小UIImage对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当用户对我的应用程序执行标准收缩操作时,我想放大/缩小UIImage对象。我目前正在使用UIImageView显示我的图片,如果这个细节以任何方式帮助。

I would like to zoom in/out an UIImage object when the user performs the standard pinch action on my application. I'm currently using a UIImageView to display my image, if that detail helps in any way.

我想知道如何做到这一点,但没有

I'm trying to figure out how to do this, but no such luck so far.

任何线索?

推荐答案

这样做是将 UIImageView 放置在 UIScrollView 中。 我在此处介绍,您需要将滚动视图的contentSize设置为与您的 UIImageView的大小相同。将控制器实例设置为滚动视图的委托,并实现 viewForZoomingInScrollView: scrollViewDidEndZooming:withView:atScale:允许缩放缩放和图像平移的方法。这是Ben的解决方案,只是稍微更轻量级的方式,因为你没有一个完整的网络视图的开销。

Another easy way to do this is to place your UIImageView within a UIScrollView. As I describe here, you need to set the scroll view's contentSize to be the same as your UIImageView's size. Set your controller instance to be the delegate of the scroll view and implement the viewForZoomingInScrollView: and scrollViewDidEndZooming:withView:atScale: methods to allow for pinch-zooming and image panning. This is effectively what Ben's solution does, only in a slightly more lightweight manner, as you don't have the overhead of a full web view.

一个问题,你可以运行滚动视图中的缩放是以应用于图像的变换的形式出现的。这可能导致高缩放系数下的模糊。对于可以重绘的内容,您可以按照我们的建议这里以在捏合手势完成之后提供更清晰的显示。 hniels'解决方案可以在这一点上重新缩放您的图像。

One issue you may run into is that the scaling within the scroll view comes in the form of transforms applied to the image. This may lead to blurriness at high zoom factors. For something that can be redrawn, you can follow my suggestions here to provide a crisper display after the pinch gesture is finished. hniels' solution could be used at that point to rescale your image.

这篇关于当用户捏住屏幕时如何放大/缩小UIImage对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆