如何重置(即取消缩放)UIScrollView? [英] How do I reset (i.e. un-zoom) a UIScrollView?

查看:558
本文介绍了如何重置(即取消缩放)UIScrollView?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个UIScrollView包含一个图像和一个分段控件,允许用户切换到ScrollView中的图像。如果我只是在UIImageView内部交换图像,它将显示放大状态下的新图像。如何将UIScrollView重置为其未放大状态?

解决方案

为什么)UIScrollView缩放在 github.com/andreyvit/ScrollingMadness/ 上运行。



(链接还包含如何以编程方式缩放UIScrollView,如何模拟照片库风格的分页+缩放+滚动,示例项目和ZoomScrollView类封装一些缩放魔术的描述。 )



报价:



UIScrollView没有当前缩放级别的概念,它包含可能有自己当前的缩放级别。请注意,UIScrollView中没有保留当前缩放级别的字段。但是,我们知道有人存储缩放级别,因为如果您捏合缩放子视图,然后将其变换重置为CGAffineTransformIdentity,然后再次缩放,您会注意到子视图的上一个缩放级别已恢复。

事实上,如果你看看反汇编,它是UIView存储自己的缩放级别(在_gestureInfo字段指向的UIGestureInfo对象内)。它还有一组很好的未记录的方法,如 zoomScale setZoomScale:animated:。 (注意,它也有一堆与旋转相关的方法,也许我们很快就会得到旋转手势支持。)



但是,如果我们创建一个新的UIView只是为了缩放和添加我们真正的可缩放视图作为它的孩子,我们将始终从缩放级别1.0开始。我的程序化缩放的实现是基于这个技巧。


I have a UIScrollView that contains an image and a segmented control that allows the user to switch the image inside of the ScrollView. If I just swap the image out inside of the UIImageView, it will display the new image in the zoomed-in state. How do I reset the UIScrollView back to its un-zoomed-in state?

解决方案

I have a detailed discussion of how (and why) UIScrollView zooming works at github.com/andreyvit/ScrollingMadness/.

(The link also contains a description of how to programmatically zoom UIScrollView, how to emulate Photo Library-style paging+zooming+scrolling, an example project and ZoomScrollView class that encapsulates some of the zooming magic.)

Quote:

UIScrollView does not have a notion of a "current zoom level", because each subview it contains may have its own current zoom level. Note that there is no field in UIScrollView to keep the current zoom level. However we know that someone stores that zoom level, because if you pinch-zoom a subview, then reset its transform to CGAffineTransformIdentity, and then pinch again, you will notice that the previous zoom level of the subview has been restored.

Indeed, if you look at the disassembly, it is UIView that stores its own zoom level (inside UIGestureInfo object pointed to by the _gestureInfo field). It also has a set of nice undocumented methods like zoomScale and setZoomScale:animated:. (Mind you, it also has a bunch of rotation-related methods, maybe we're getting rotation gesture support some day soon.)

However, if we create a new UIView just for zooming and add our real zoomable view as its child, we will always start with zoom level 1.0. My implementation of programmatic zooming is based on this trick.

这篇关于如何重置(即取消缩放)UIScrollView?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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