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

查看:25
本文介绍了用户捏合屏幕时如何放大/缩小 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's 大小相同.将您的控制器实例设置为滚动视图的委托,并实现 viewForZoomingInScrollView:scrollViewDidEndZooming:withView:atScale: 方法以允许缩放和图像平移.这正是 Ben 的解决方案所做的,只是以稍微轻巧的方式完成,因为您没有完整的 Web 视图的开销.

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天全站免登陆