制作一个带有 HGroup“捕捉”功能的 Flex/AIR 滚动条滚动完成时到每个项目

发布于 2024-10-19 00:52:14 字数 1796 浏览 6 评论 0原文

我正在使用 Flash Builder Burrito 为 ANDROID 设备开发一款应用程序,但我无法弄清楚如何完成我的应用程序的一个方面。

我在 Scroller 中有一个 HGroup。 HGroup 的图像宽度为 400 像素,我将每个 HGroup 列的宽度设置为 400 像素。尽管项目数量是动态的,但假设 HGroup 中有 10 个图像。 Scroller 和 Viewport 的宽度设置为 400px。

到目前为止一切顺利——用户可以在滚动条中看到单个图像。然后,用户可以使用触摸或鼠标向左或向右滚动并查看每个图像。但这就是我被困住的地方。我想做到这一点,以便当用户停止滚动滚动条时,然后将图像“捕捉”到视图中。换句话说,我不想在视口中显示一张图像的一半和另一张图像的一半。

看起来很简单,但我无法弄清楚。部分问题是似乎没有可用于此目的的事件。我知道我可以连接到 PropertyChangeEvent.PROPERTY_CHANGE 或 MouseEvent.MOUSE_UP/TouchEvent.TOUCH_END (这就是我现在正在做的事情),但该事件并没有真正给我我需要的东西。

我确实需要一个事件,当用户作为滚动的一部分释放鼠标或作为滚动的一部分将手指从设备上抬起时触发。 然后我需要等待滚动停止。例如,如果我进行非常快速的滑动,我需要等待滚动条停止或几乎停止,然后再执行捕捉。一旦我放开鼠标或将手指从平板电脑上移开,该事件就会触发,因此如果我更改水平滚动位置,那么它就会被“滚动条减慢”覆盖。

顺便说一句,我知道我可以使用模逻辑来“完整”地显示每个图像。这不是我被困住的地方——我被困在使用哪个事件来知道何时执行这个 mod 逻辑。

请注意,如果我慢慢滚动然后松开鼠标,我已经开发的内容就可以正常工作。只有当你滑动得更快时它才会停止工作。

这是我的部分工作代码:

private function onVehicleScrollerMouseUp(event:Event):void
{
    snapScroller();
}

private function onVehicleScrollerTouchEnd(event:Event):void
{
    snapScroller();
}

private function snapScroller():void
{
    // If the user didn't stop at an interval of 400, snap to that interval now
    var newScrollPosition:uint = vehicleScroller.viewport.horizontalScrollPosition as uint; 
    var modScrollPosition:uint = newScrollPosition % 400;
    var snapScrollPosition:uint;
    if (modScrollPosition == 0)
        snapScrollPosition = newScrollPosition;
    else
    {
        if (modScrollPosition <= 200)
            snapScrollPosition = newScrollPosition - modScrollPosition;
        else
            snapScrollPosition = newScrollPosition - modScrollPosition + 400; 
    }
    vehicleScroller.viewport.horizontalScrollPosition = snapScrollPosition as Number;
}

提前致谢!

I'm developing an app for ANDROID devices using Flash Builder Burrito and am having trouble figuring out how to accomplish one aspect of my app.

I have an HGroup inside of a Scroller. The HGroup has images that are 400px in width and I have the width of each HGroup column set to 400px. Although the number of items is dynamic, assume I have 10 images in the HGroup. The width of the Scroller and Viewport is set to 400px.

So far so good -- the user can see a single image within the scroller. The user can then scroll left or right using touch or mouse and see each image. But here's where I'm stuck. I want to make it so that when the user STOPS scrolling the scroller then "snaps" an image into view. In other words, I don't want half of one image and half of another image in the viewport.

Seems pretty straightforward but I can't figure it out. Part of the issue is that there doesn't seem to be an event to use for this purpose. I know I can hook in to PropertyChangeEvent.PROPERTY_CHANGE or MouseEvent.MOUSE_UP/TouchEvent.TOUCH_END (which is what I'm doing now) but that event doesn't really give me what I need.

I really need an event that fires when the user releases the mouse as part of the scroll or lifts their finger off the device as part of the scroll. And then I need to wait for the scroll to stop. For example, if I do a really fast swipe I need to wait for the scroller to stop or almost stop before I perform the snap. The event fires as soon as I let go of the mouse or take my finger off the tablet, so if I alter the horizontal scroll pos then it gets overwritten by the "slowing down of the scroller".

By the way, I know I can use modulus logic to show each image "whole". That's not where I'm stuck -- I'm stuck at which event to use to know WHEN to perform this mod logic.

Note that what I've already developed works just fine if I slowly scroll and then let off the mouse. It's only when you slide more rapidly that it ceases to work.

Here's my partially working code:

private function onVehicleScrollerMouseUp(event:Event):void
{
    snapScroller();
}

private function onVehicleScrollerTouchEnd(event:Event):void
{
    snapScroller();
}

private function snapScroller():void
{
    // If the user didn't stop at an interval of 400, snap to that interval now
    var newScrollPosition:uint = vehicleScroller.viewport.horizontalScrollPosition as uint; 
    var modScrollPosition:uint = newScrollPosition % 400;
    var snapScrollPosition:uint;
    if (modScrollPosition == 0)
        snapScrollPosition = newScrollPosition;
    else
    {
        if (modScrollPosition <= 200)
            snapScrollPosition = newScrollPosition - modScrollPosition;
        else
            snapScrollPosition = newScrollPosition - modScrollPosition + 400; 
    }
    vehicleScroller.viewport.horizontalScrollPosition = snapScrollPosition as Number;
}

Thanks in advance!

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

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

发布评论

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

评论(2

童话 2024-10-26 00:52:14

Multitouch.inputMode = MultitouchInputMode.GESTURE;

然后监听gesturePan和/或gestureSwipe事件。

Multitouch.inputMode = MultitouchInputMode.GESTURE;

Then listen to gesturePan and/or gestureSwipe events.

飘过的浮云 2024-10-26 00:52:14

touchInteractionEnd 事件将在用户释放手指并且滚动动画停止后调度。当我的页面捕捉随机中断并且需要手动捕捉到某个页面时,我遇到了这个问题。

The touchInteractionEnd event will dispatch after the user has released their finger and the scroll animation has stopped. I ran into this issue when my page snapping broke randomly and needed to manually snap to some page.

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