阻止UIScrollView将内容移动到左上角

编程入门 行业动态 更新时间:2024-10-25 08:22:55
本文介绍了阻止UIScrollView将内容移动到左上角的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我在 UIScrollView 中包含 UIImageView 。图像(通常)很大,因此用户可以将其缩小以查看整个图像。

I have a UIImageView contained within a UIScrollView. The image is (usually) big, so the user can zoom it out in order to see the whole thing.

在缩小时, UIScrollView 将 ImageView 捕捉到scrollview的左上角。我希望用户可以定位它,并且还没有找到关闭它的方法。

Upon zooming out, though, UIScrollView snaps the ImageView to the top-left of the scrollview. I want this to be positionable by the user, and haven't found a way to "turn it off" yet.

有点像总是允许滚动,而不仅仅是允许在图像放大时滚动。也许它太重要了?

It's kinda like always allowing scrolling, rather then only allowing scrolling when the image is zoomed in. Maybe it's too major of a change?

任何人都知道方法吗?最初,我只是想手动创建这个功能。但UIImageViews不喜欢调整到新的大小(我已经尝试了所有的东西,并且无法获得 UIImageView 来调整大小,除非我从 imageView ,更改框架,然后重新添加。)

Anyone know of a way? Originally, I was just going to create this functionality manually. But UIImageViews don't like to adjust to new sizes (I've tried about everything and can't get UIImageView to resize UNLESS I remove the picture from the imageView, change the frame, and re-add it).

推荐答案

我最终了禁用 UIScrollView 的 panGestureRecognizer 并在自定义中进行修补。

I ended up disabling the UIScrollView's panGestureRecognizer and subbing in a custom one.

以下是关于如何禁用它的快速摘录:

Here's a quick snippet on how to disable it:

// Disable our GestureRecognizer for (UIGestureRecognizer *gesture in scrollView.gestureRecognizers){ if ([[NSString stringWithFormat:@"%@",[gesture class]] isEqualToString:@"UIScrollViewPanGestureRecognizer"]){ [gesture setEnabled:NO]; break; } }

那里有一些黑客工作,但它是由于 UIScrollViews 已将GestureRecognizer的类更改为UIScrollViewPanGestureRecognizer。如果你尝试使用那个类,编译器会对你大喊大叫(那里可能有更好的解决方案)。

A bit of a hack-job there, but it's due to the fact that UIScrollViews have changed the class of the GestureRecognizer to "UIScrollViewPanGestureRecognizer." The compiler will yell at you if you try to use that class (there's probably a better solution out there).

更多推荐

阻止UIScrollView将内容移动到左上角

本文发布于:2023-07-18 04:51:50,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1141179.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:左上角   内容   UIScrollView

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!