iPhone:如何在捏缩放 uiscrollview 时重绘子视图

发布于 2024-08-20 03:56:06 字数 626 浏览 4 评论 0原文

我正在开发一个 iPhone 应用程序,它将多个自定义 UIView 作为子视图放置在 UIScrollView 中。子视图作为透明视图放置在彼此之上,因为每个视图都有自己的绘图例程来跟踪基础视图的各个部分。基本视图是一个 UIImageView,它通常是一个大图像,我希望用户能够平移和放大和缩小。

我遇到的问题是,当我放大和缩小 UIScrollView 时,子视图在用户缩放时不会重新绘制自身。缩放完成后,我可以正确地重新定位和缩放子视图,但用户体验不太理想。我无法找到隐藏或重绘子视图的方法,因为正在缩放子视图以及 ImageView。

有什么想法吗?

谢谢!

这是我已经实现的代码:

- (void)scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(UIView *)view atScale:(float)scale {

 for (UIView *view in subViews)
 {
  [view updateView:scale];
 }
}

- (UIView *)viewForZoomingInScrollView:(UIScrollView *) scrollView {
 return imageView;
}

I am developing an iPhone app that places multiple custom UIViews as subviews in a UIScrollView. The subviews are placed on top of each other as transparent views as each view has its own drawing routines that traces parts of the base view. The base view is a UIImageView that is typically a large image that I want the user to be able to pan and zoom in and out of.

The problem I am having is that when I zoom in and out of my UIScrollView, the subviews do not redraw themselves while the user is zooming. I can reposition and scale the subviews properly once the zoom is completed, but the user experience is less than desirable. I have not been able to find a way to either hide or redraw the subviews as the zoom is taking place to scale the subviews along with the ImageView.

Any ideas?

thanks!

Here is the code that I have implemented:

- (void)scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(UIView *)view atScale:(float)scale {

 for (UIView *view in subViews)
 {
  [view updateView:scale];
 }
}

- (UIView *)viewForZoomingInScrollView:(UIScrollView *) scrollView {
 return imageView;
}

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

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

发布评论

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

评论(3

树深时见影 2024-08-27 03:56:06

在 >=3.2 中现在有:
- (void)scrollViewDidZoom:(UIScrollView *)scrollView

所以在未来的某一天这将是一个明智的解决方案。

In >=3.2 there is now:
- (void)scrollViewDidZoom:(UIScrollView *)scrollView

So some day in the future this will be the sensible solution to this.

溺渁∝ 2024-08-27 03:56:06

您从 viewForZoomingInScrollView: 返回的 imageView 将随着视图缩放而调整大小。您可以在该视图中实现 setFrame: 或更标准的 layoutSubviews 来进行更新。滚动视图的 contentSize 也会在缩放过程中不断更新,因此您可以在自定义滚动视图中实现 setContentSize:

The imageView that you are returning from viewForZoomingInScrollView: will be resized as the view zooms. You could implement setFrame: or the more standard layoutSubviews in that view to do your updating. The contentSize of the scroll view is also updated continually during zooming, so you could implement setContentSize: in a custom scroll view.

酒废 2024-08-27 03:56:06

我不知道实现它的正确方法,但我为您提供了解决方法

由于 viewForZoomingInScrollView 是在之前调用的缩放和scrollViewDidEndZooming - 之后,您可以使用viewForZoomingInScrollView在单独的线程中调用方法。该方法将每 100 毫秒(或任何其他看起来不错的时间段)检查 UIScrollViewzoomScale 并进行所有需要的更改。在 scrollViewDidEndZooming 中,您将停止新方法的执行。

I don't know a proper way to implement it, but I have a work-around for you:

Since the viewForZoomingInScrollView is called right before the zooming and scrollViewDidEndZooming - right after, you could use the viewForZoomingInScrollView to call a method in a separate thread. That method will check the zoomScale of your UIScrollView each 100 milliseconds (or any other period that would look good) and will make all the needed changes. In scrollViewDidEndZooming you will stop the execution of the new method.

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