如何实现我自己的缩放但仍然可以访问 UIScrollView 的滚动?

发布于 2024-07-13 02:46:02 字数 382 浏览 5 评论 0原文

我想使用 UIScrollView 的滚动/平移功能,但我想自己处理所有缩放和缩放。 我当前的计划是拥有一个拥有 UIView(我将其称为 view1)的 viewController,其中包含多个 UIView 和 UIScrollView 作为子项。

view1 是否可以处理所有多点触摸事件(以便手动渲染所有子级的缩放状态)并将结果绘制到每个相应的滚动视图上以允许用户滚动结果?

(出于好奇,应用程序正在绘制多个热图,每个热图都有自己的一组轴。在缩放或滚动时,轴需要更新自身以正确标记数据区域(滚动视图)中表示的范围。我的原因不能使用scrollView免费提供的默认上下文图像缩放缩放是在上下文缩放上绘制的任何内容(包括参考线之类的内容)缩放操作实际上并不是使事物变大而是调整可视范围。数据范围。)

I would like to use the scrolling/panning functionality of the UIScrollView but I would like to handle all the zooming and scaling myself. My current plan is to have a viewController that owns a UIView (I'll call it view1) with multiple UIViews and UIScrollViews as children.

Is it possible for view1 to handle all multi-touch events (in order to manually render all his children's zoomed states) and draw the results onto each respective scroll view to allow a user to scroll around the results?

(For the curious, the application is drawing multiple heatmaps, each with its own set of axes. While zooming or scrolling, the axes need to update themselves to correctly label the ranges represented in the data region (the scroll view). The reason I can't use the default context-image-scaling zoom that comes for free with the scrollView is that ANYthing drawn on the context zooms (including things like reference lines). The zooming action is not to actually make things bigger but to adjust the viewable data range.)

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

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

发布评论

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

评论(2

绮烟 2024-07-20 02:46:02

您确实可以让主托管视图拦截多点触控事件并以编程方式缩放底层 UIView。 这就是我在 我的应用程序 的 OpenGL 显示部分所做的事情(来源可用 此处)。 您仍然可以将单点触摸事件传递到底层滚动视图以进行平移等。

但是,仍然可能有一种方法可以在不拦截触摸事件的情况下执行您所描述的操作。 UIScrollView 通过对内容视图应用转换来执行默认缩放。 为了回答这个问题,我描述一种在捏缩放完成后以新比例重新渲染内容视图的方法。 缩放完成后,这将使您可以使用清晰的网格线刷新绘图。

此外,如果您没有真正缩放并且想要通过捏缩放来更改视图的另一个属性,您可以执行我在该问题中描述的操作并拦截 contentView 上的转换设置,只是不要应用转换。 您可以从该转换中提取 UIScrollView 想要设置的比例,并根据需要对视图进行自定义重绘。

You can indeed have the main hosting view intercept multitouch events and do scaling of the underlying UIViews programmatically. It's what I do in the OpenGL display portion of my application (source available here). You could still pass on single-touch events to the underlying scroll view for panning, etc.

However, there still might be a way to do what you describe without intercepting the touch events. UIScrollView does its default scaling by applying a transform to your content view. In response to this question, I describe a way to re-render your content view at the new scale once the pinch zooming has finished. This would let you refresh your drawing with sharp grid lines once the zoom is done.

Additionally, if you're not really scaling and you want to change another property of your view with the pinch zooming, you can do what I describe in that question and intercept the setting of the transform on your contentView, only don't apply the transform. You can extract the scale that the UIScrollView wants to set from that transform, and do your own custom redraw of the view in response.

此生挚爱伱 2024-07-20 02:46:02

感谢您的建议布拉德。 我最终使用的解决方案是扩展 UIScrollView 并使用以下方法重写 TouchMoved:withEvent: 方法:

-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
    if ([[event touchesForView:self] count] == 1) 
         [super touchesMoved:touches withEvent:event];
    [content touchesMoved:touches withEvent:event];
}

其中“content”是指向我的滚动视图的内容子视图的指针。 我必须这样做,因为我的内容需要缩放到点(即,用户手指下的数据空间中的点不应改变)。 发送到 setTransform: 的信息只能告诉我内容帧的大小,但我还需要它的偏移量。

Thanks for your suggestion brad. the solution I ended up using was to extend UIScrollView and override the touchesMoved:withEvent: method with this:

-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
    if ([[event touchesForView:self] count] == 1) 
         [super touchesMoved:touches withEvent:event];
    [content touchesMoved:touches withEvent:event];
}

where "content" is a pointer to my scrollview's content subview. I had to do it this way because my content needs to zoom-to-point (ie, the points in data-space under the user's fingers shouldn't change). The information sent to setTransform: can only tell me the size of the content frame, but I also need the offset into it.

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