UIScrollView 在 iOS 4.0 上缩放时不调用 layoutSubviews

发布于 2024-11-03 12:47:00 字数 511 浏览 3 评论 0原文

我读过这里提出的许多 UIScrollView 问题,但没有一个回答这个问题。

我有一个 UIScrollView 可以缩放包含其他子视图的视图。当发生缩放时,我需要将视图的子视图移动到某些位置。我可以通过在 UIScrollView 的 layoutSubviews 方法中相应地更改它们的框架来实现此目的。

在 iOS 3.2 及更低版本上,这对于手指缩放和使用 ZoomToRect:animated: 方法进行实用缩放都非常有效。

在 iOS 4.0 或更高版本上,这只适用于手指缩放。通过使用zoomToRect:animated:进行实用缩放,对layoutSubviews的调用仅发生一次(在缩放结束时)。我需要在缩放期间多次调用此方法,以便我的子视图可以随着缩放而平滑位置变化。

总而言之,在 iOS 3.2 上,对layoutSubviews 的调用会发生很多次,而在 iOS 4.0 上,当您调用 ZoomToRect:animated: 时,对layoutSubviews 的调用只会发生一次。有谁知道我的问题的解决方案?

I've read many of the UIScrollView questions asked on here but none of them answered this problem.

I have a UIScrollView that zooms a view containing other subviews. When a zoom is happening, I need to have the subviews of the view move to certain places. I can accomplish this by changing their frames accordingly in the layoutSubviews method of the UIScrollView.

On iOS 3.2 and lower, this works great both for finger-zooming and pragmatic zooming using zoomToRect:animated: method.

On iOS 4.0 or higher, this only works great for finger-zooming. With pragmatic zooming using zoomToRect:animated:, a call to layoutSubviews only happens once (at the end of the zoom). I need this method to get called many times during the duration of the zoom so that my subviews can have smooth position changes along with the zoom.

So in summary, on iOS 3.2, a call to layoutSubviews happens many times and on iOS 4.0 a call to layoutSubviews happens only once when you call zoomToRect:animated:. Does anyone know of a solution to my problem?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

你丑哭了我 2024-11-10 12:47:00

在 iOS 4.0 中,动画是由操作系统完成的 - 我假设尽可能利用基于 GPU 的硬件加速。其缺点是,对从另一个(动画)值派生的值进行动画处理变得更加困难。就像您的情况一样,子视图的位置取决于 UIScrollView 的缩放级别。
为了实现这一点,您应该将子视图的动画设置为与缩放动画并行。尝试类似的操作:

[UIView animateWithDuration:0.5 delay:0
                    options:UIViewAnimationOptionLayoutSubviews
                 animations:^{
    theScrollView.zoomScale = zoomScale;
    [theScrollView layoutSubViews];
} completion:^(BOOL finished) {}];

这应该在同一动画上下文中设置子视图的帧属性,因此,它们应该由操作系统一起进行动画处理。
我不确定是否需要显式的layoutSubViews,或者 UIViewAnimationOptionLayoutSubviews 选项是否已经实现了这一点。

另请参阅此问题的答案:如何使 UIScrollView 发送scrollViewDidScroll动画期间的消息

In IOS 4.0, animations are done by the OS - I assume to make use of GPU based hardware acceleration as much as possible. As a disadvantage of that, it becomes harder to animate a values that is derived from another (animated) value. As in your case, the positions of the subviews that depend on the zoom level of the UIScrollView.
In order to make that happen, you should setup the animation of the subviews to go in parallel with the animation of the zooming. Try something like:

[UIView animateWithDuration:0.5 delay:0
                    options:UIViewAnimationOptionLayoutSubviews
                 animations:^{
    theScrollView.zoomScale = zoomScale;
    [theScrollView layoutSubViews];
} completion:^(BOOL finished) {}];

This should set the frame properties of the subviews from within the same animation context, and therefore, they should be animated together by the OS.
I am not sure whether the explicit layoutSubViews is needed, or whether the UIViewAnimationOptionLayoutSubviews option already achieves that.

See also the answers to this question: How to make UIScrollView send scrollViewDidScroll messages during animations

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文