gpt4 book ai didi

ios - UIScrollView 如何改变框架,而不是边界? UIScrollView 是如何工作的?

转载 作者:行者123 更新时间:2023-12-01 15:56:15 27 4
gpt4 key购买 nike

我理解框架和边界之间的区别,我认为边界是 View 的局部坐标系,而框架是父 View 。

然而,对于 ScrollView ,我有点困惑。

当我在 UIScrollView 中有一个 UIImageView 并捏合以将其放大时,似乎框架变大(宽度和高度)也会增加相应 UIImage 的宽度和高度。

但是,UIImageView 的边界似乎根本没有改变。

这是为什么? ScrollView 如何处理所有这些?我已经阅读了多个问题并检查了文档,但这个解释让我难以理解。

放大 UIScrollView 如何影响其内容?它是否只是改变缩放 View 的框架而不改变边界?

最佳答案

查看说明in my book :

The scroll view zooms by applying a scaling transform to the scalable view; therefore the frame of the scalable view is scaled as well. Moreover, the scroll view is concerned to make scrolling continue to work correctly: the limits as the user scrolls should continue to match the limits of the content, and commands like scrollRectToVisible:animated: should continue to work the same way for the same values. Therefore, the scroll view automatically scales its own contentSize to match the current zoomScale. (You can actually detect this happening by overriding setContentSize in a UIScrollView subclass: you can see the scroll view adjusting its own content size as you zoom.)

基本上(虽然从上面的引文中还不是很清楚)我们与可伸缩 View 的框架无关 - 或者任何 View - 应用了非身份转换它,这里正是这种情况。关于 UIView 的 Apple 文档非常清楚地说明了这一事实。因此你不应该看框架 - 只看变换。您正在读取的帧的变化纯粹是转换变化的副作用。

至于可伸缩 View 的边界——显然边界不会改变;这就是转换如何工作的全部要点。它保持恒定的 centerbounds,因此尽管发生了变换, subview 和绘图仍能在引用框架坐标内继续正确运行。我的书talks you through对此也有所了解。

另一方面, ScrollView 自身的边界当然可以改变它们的原点,尤其是因为这与 ScrollView 滚动的含义完全相同。滚动边界原点的改变,简单明了。这在缩放期间并不奇怪,因为正如我刚才所说,内容大小已经改变,因此内容可能会重新定位,以便在缩放时保持连贯显示。

关于ios - UIScrollView 如何改变框架,而不是边界? UIScrollView 是如何工作的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21690794/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com