UIScrollView 垂直平移对齐到视图的顶部或底部

发布于 2024-09-28 13:56:34 字数 682 浏览 6 评论 0原文

我有一个 320x480 的图像,当方向改变时,该图像显然会挂在视图之外。有一些图像的焦点位于其底部被切除的位置(这并非不可取)。然而,我的问题是,当用户垂直平移以查看完整图像时,视图似乎会捕捉到底部,这意味着焦点的顶部被切断。我希望发生的是,用户可以“自由滚动”图像,或许还可以移动图像,使焦点位于屏幕中央,而不是切断顶部和底部。我知道这是一个很难用语言描述的概念,所以我在下面附上了一些图片。

这是它的开始方式:

alt text

这是它捕捉到底部的位置:

alt text

这是我希望拥有但无法获得的视图:

alt text

有没有一种方法可以控制这种“捕捉”,或者在专门处理这种方向时我可以使用一种方法来覆盖它?我的问题是,我希望它在向左/向右平移到 ScrollView 中的其他图像上时捕捉,而不是向上/向下。

编辑:

pagingEnabled 是控制此捕捉的属性,但是是否有办法检测移动是上/下还是左/右,并在每种情况下禁用或启用此属性?

为您能提供的任何帮助干杯

I have an image that is 320x480 and upon orientation change this image obviously hangs out of view. There are some images where the focal point of it sits with it's bottom cut off (which isn't undesirable). My issue however is when the user pans vertically to see the full image, the view appears to snap to the bottom meaning the top of the focal point is cutoff. What I wish to happen is that the users can "free-scroll" through the image and perhaps move the images so the focal point is centre screen, instead of cutting off the top and bottom. I understand this is a difficult concept to describe in words so I've attached some images below.

This is how it starts:

alt text

This is where it snaps to the bottom:

alt text

This is the kind of view I wish to have but cannot:

alt text

Is there a way to control this "snapping" or perhaps a method I could use to override it when dealing specifically with this kind of orientation? My issue is that i WANT it to snap when panning left/right onto the other images in the ScrollView, just not up/down.

EDIT:

pagingEnabled is the property that controls this snapping, but is there anyway to detect if the movement is Up/Down or Left/Right and disable or enable this property in each occasion?

Cheers for any help you can offer

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

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

发布评论

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

评论(1

暗喜 2024-10-05 13:56:34

您可以尝试使用两个嵌套的滚动视图;一种仅限于在启用分页的情况下水平滚动,另一种(或者如果您要显示多张图像,则每页一个?)仅限于在禁用分页的情况下垂直滚动。默认情况下,这将像您所说的那样工作,水平分页/捕捉,但垂直自由滚动。但是,它一次只能让您向一个方向滚动(水平或垂直,而不是对角)。

如果您想使用这样的嵌套滚动视图,但又想允许同时在两个方向上滚动/拖动,请查看我的解决方案:嵌套的 UIScrollViews 同时滚动

You can try using two nested scroll views; one is limited to scrolling horizontally with paging enabled, and one (or one for each page if you're displaying several images?) limited to scrolling vertically with paging disabled. By default this will work like you said, paging/snapping horizontally but free scroll vertically. However, it will only let you scroll in one direction at a time (either horizontally or vertically, not diagonally).

If you want to use nested scroll views like this but you'd like to allow scrolling/dragging in both directions simultaneously, take a look at my solution for this: Nested UIScrollViews scrolling simultaneously

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