如何实现循环滚动机制?

时间:2020-12-07 14:34:26

I'm having some images from which the user should choose one. Now I don't want to just offer an flat scrolling area with a boring grid. Instead, I'd like to show up a wheel that contains those images. At the top would be a marker indicating the selection. Something similar to the Pickers.

我有一些用户应该从中选择的图像。现在我不想只提供一个带有无聊网格的平面滚动区域。相反,我想展示一个包含这些图像的*。在顶部将是指示选择的标记。类似于采摘者的东西。

The problem is not the rotation stuff; I'd use some geometric functions for that. But I have no idea how to actually get the scrolling gestures on that wheel. Where must I start?

问题不在于旋转的东西;我会使用一些几何函数。但我不知道如何在该轮上实际获得滚动手势。我必须从哪里开始?

BTW: With circular I don't mean something like the Pickers. I mean a real wheel that has a center axis and can be rolled. Like the very old telephones, like a bike wheel. Or a Picker turned by 90°, facing with the axis to you (Z-coordinate).

顺便说一句:通过循环我并不是指像拾取器那样的东西。我的意思是一个真正的车轮,有一个中心轴,可以滚动。就像很老的电话,就像自行车车轮一样。或者选择器旋转90°,面向轴(Z坐标)。

2 个解决方案

#1


If you're talking about capturing gestures then here is the example they give in the docs.

如果您正在谈论捕获手势,那么这里是他们在文档中给出的示例。

Though I could have sworn I heard Alan Cannistraro say in one of the first CS193P lectures that you don't have to do this, that you can just trap the swipe event but I can't find that.

虽然我可以发誓我听到Alan Cannistraro在第一次CS193P讲座中说你不必这样做,你可以抓住滑动事件,但我找不到。

Could someone that actually knows what they are doing please correct me and I'll remove this post but for now I know this will work:

有人真的知道他们在做什么请纠正我,我会删除这篇文章,但现在我知道这将有效:

#define HORIZ_SWIPE_DRAG_MIN  12
#define VERT_SWIPE_DRAG_MAX    4

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    UITouch *touch = [touches anyObject];
    startTouchPosition = [touch locationInView:self];
}

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
    UITouch *touch = [touches anyObject];
    CGPoint currentTouchPosition = [touch locationInView:self];

    // If the swipe tracks correctly.
    if (fabsf(startTouchPosition.x - currentTouchPosition.x) >= HORIZ_SWIPE_DRAG_MIN &&
        fabsf(startTouchPosition.y - currentTouchPosition.y) <= VERT_SWIPE_DRAG_MAX)
    {
        // It appears to be a swipe.
        if (startTouchPosition.x < currentTouchPosition.x)
            [self myProcessRightSwipe:touches withEvent:event];
        else
            [self myProcessLeftSwipe:touches withEvent:event];
    }
    else
    {
        // Process a non-swipe event.
    }
}

#2


Just how similar to a picker view are you thinking? You can load up a picker view with your own custom subviews, which could be image views. That'd get you an actual picker view with your images, which might or might not be what you're actually aiming for.

你在想什么类似于选择器视图?您可以使用自己的自定义子视图加载选取器视图,这可能是图像视图。这会让你获得一个真实的选择器视图与你的图像,这可能是你可能实现或可能不是你的目标。

#1


If you're talking about capturing gestures then here is the example they give in the docs.

如果您正在谈论捕获手势,那么这里是他们在文档中给出的示例。

Though I could have sworn I heard Alan Cannistraro say in one of the first CS193P lectures that you don't have to do this, that you can just trap the swipe event but I can't find that.

虽然我可以发誓我听到Alan Cannistraro在第一次CS193P讲座中说你不必这样做,你可以抓住滑动事件,但我找不到。

Could someone that actually knows what they are doing please correct me and I'll remove this post but for now I know this will work:

有人真的知道他们在做什么请纠正我,我会删除这篇文章,但现在我知道这将有效:

#define HORIZ_SWIPE_DRAG_MIN  12
#define VERT_SWIPE_DRAG_MAX    4

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    UITouch *touch = [touches anyObject];
    startTouchPosition = [touch locationInView:self];
}

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
    UITouch *touch = [touches anyObject];
    CGPoint currentTouchPosition = [touch locationInView:self];

    // If the swipe tracks correctly.
    if (fabsf(startTouchPosition.x - currentTouchPosition.x) >= HORIZ_SWIPE_DRAG_MIN &&
        fabsf(startTouchPosition.y - currentTouchPosition.y) <= VERT_SWIPE_DRAG_MAX)
    {
        // It appears to be a swipe.
        if (startTouchPosition.x < currentTouchPosition.x)
            [self myProcessRightSwipe:touches withEvent:event];
        else
            [self myProcessLeftSwipe:touches withEvent:event];
    }
    else
    {
        // Process a non-swipe event.
    }
}

#2


Just how similar to a picker view are you thinking? You can load up a picker view with your own custom subviews, which could be image views. That'd get you an actual picker view with your images, which might or might not be what you're actually aiming for.

你在想什么类似于选择器视图?您可以使用自己的自定义子视图加载选取器视图,这可能是图像视图。这会让你获得一个真实的选择器视图与你的图像,这可能是你可能实现或可能不是你的目标。