如何以编程方式缩放UIScrollView? [英] How do I programmatically zoom a UIScrollView?

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

问题描述

我想以基类不支持的方式缩放和解缩。



例如,在收到双击时。

解决方案

我正在回答我自己的问题,在玩完东西并让它正常工作之后。



<在他们关于如何处理双击的文档中,Apple有一个非常简单的例子。



执行程序化缩放的基本方法是自己动手,然后告诉UIScrollView你做到了。




  • 调整内部视图的框架和边界。

  • 将内部视图标记为需要显示。

  • 告诉UIScrollView有关新内容的大小。

  • 计算
    内部视图中应显示为
    的部分在缩放之后,将
    的UIScrollView平移到
    位置。



同样关键:一旦告诉关于你的新内容大小的UIScrollView似乎重置了它当前缩放级别的概念。您现在处于新的1.0缩放系数。所以你几乎肯定想要重置最小和最大缩放系数。


I'd like to zoom and unzoom in ways the base class doesn't support.

For instance, upon receiving a double tap.

解决方案

I'm answering my own question, after playing with things and getting it working.

Apple has a very-simple example of this in their documentation on how to handle double taps.

The basic approach to doing programmatic zooms is to do it yourself, and then tell the UIScrollView that you did it.

  • Adjust the internal view's frame and bounds.
  • Mark the internal view as needing display.
  • Tell the UIScrollView about the new content size.
  • Calculate the portion of your internal view that should be displayed after the zoom, and have the UIScrollView pan to that location.

Also key: once you tell the UIScrollView about your new contents size it seems to reset its concept of the current zoom level. You are now at the new 1.0 zoom factor. So you'll almost certainly want to reset the minimum and maximum zoom factors.

这篇关于如何以编程方式缩放UIScrollView?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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