0

いくつかの画像があり、それらの画像はすべて独自の UIImageView に配置されています。画像を移動する複数のポイントを含む NSArray があります。すべての画像は相互に追従する必要があり、10 個の画像のうち 5 個のみが同時にそのトラック上にある可能性があります (ユーザー設定)。それでも、これらの画像はパス上に均等に配置する必要があります。

私の問題は、画像を動かすことができるということですが、UIScrollView や UITableView のような「フリングまたはフリック」の動きを与えることはできません。(UIPanGesture による移動と解放時に残りの速度を使用して、画像が停止するまで速度を落としながら移動し続ける時間を計算します)。

私の UIImageViews は、あるポイントから別のポイントに移動するのではなく、最後の場所にジャンプします。私はすでにデフォルトのアニメーションを使用しようとしましたが、UIImageViews が画面を出入りすると問題が発生します。

これは、この部分(動き)だけをテストするために作成したコードです

    - (void) move: (int) direction{

    switch (direction) {
        case MOVEMENT_LEFT:
        {
            if ((currentLocation -1) <= startpoint){
                currentLocation = endpoint;
            } else {
                currentLocation--;
            }
        }
            break;
        case MOVEMENT_RIGHT:
        {
            if ((currentLocation +1) >= endpoint){
                currentLocation = startpoint;
            } else {
                currentLocation++;
            }
        }
            break;
        default:
            break;
        }
    [image setFrame:CGRectMake(currentLocation, 100, 125, 125)];
}

- (void) panHandler: (UIPanGestureRecognizer *) recognizer
{
    CGPoint velocity = [recognizer velocityInView:[self view]];
    //NSLog(@"Speed: x.%f y.%f", velocity.x, velocity.y);


    if (recognizer.state == UIGestureRecognizerStateBegan){

    } else if (recognizer.state == UIGestureRecognizerStateChanged){

        if((velocity.x < 0 && velocity.y < 0) || (velocity.x < 0 && velocity.y > 0) || (velocity.x < 0 && velocity.y == 0) || (velocity.x == 0 && velocity.y < 0))
        {
            speed = floorf(sqrtf((velocity.x * velocity.x) + (velocity.y * velocity.y)));
            gestureDirection = MOVEMENT_LEFT;
            LOG_direction = @"Left";
            [self move:MOVEMENT_LEFT];
        } else if((velocity.x > 0 && velocity.y > 0) || (velocity.x > 0 && velocity.y < 0) || (velocity.x > 0 && velocity.y == 0) || (velocity.x == 0 && velocity.y > 0))
        {
            speed = floorf(sqrtf((velocity.x * velocity.x) + (velocity.y * velocity.y)));   
            gestureDirection = MOVEMENT_RIGHT;
            LOG_direction = @"Right";
            [self move:MOVEMENT_RIGHT];
            //[image setFrame:CGRectMake(currentLocation, 100, 125, 125)];
        }

    } else if (recognizer.state == UIGestureRecognizerStateEnded || recognizer.state == UIGestureRecognizerStateFailed || recognizer.state == UIGestureRecognizerStateCancelled){
        NSLog(@"Movement %@ with start speed: %i", LOG_direction, speed);
        if (speed > 1250){
            NSLog(@"Fling Movement Event");
            //int sleeper = 0;
            if (gestureDirection == MOVEMENT_LEFT){
                for (int i = speed; i > 0; i--){
                    [image removeFromSuperview];
                    [self move:MOVEMENT_LEFT];
                    sleep(.05);
                    [[self view] addSubview:image];
                    //sleeper = sleeper + 100;
                    //sleep(sleeper);
                }
            } else {
                for (int i = speed; i > 0; i--){
                    [image removeFromSuperview];
                    [self move:MOVEMENT_RIGHT];
                    sleep(.05);
                    [[self view] addSubview:image];
                    //sleeper = sleeper + 100;
                    //sleep(sleeper);
                }
            }
        } else {
            NSLog(@"Normal Movement Event");
        }
    }

}

私が達成しようとしているのは、SINUS-WAVE上を左から右または後ろに移動するUIImageViews(ユーザーのタッチに応じて)と、左を離れる画像が右側の配列の次の画像に置き換えられることです。後ろ向き..

[画像 F] [画像 A] [画像 B] [画像 C] [画像 D] ユーザーが指を右に移動すると、[画像 G] [画像 F] [画像 A] [画像 B] [画像C] そして、フリングを使用すると、さらに前進しますが、外出先ですべての画像を表示します..

誰かが助けてくれることを願っています..

4

1 に答える 1

0

UIScrollView には、スクロール ビューのサイズをページ サイズとして取得するプロパティ「pagingEnabled」があり、スクロールすると、コンテンツの次の「ページ」に移動します。

IE: スクロール ビューのサイズは 100x100、contentSize は 400x100 です。

ただし、カスタム サイズのカスタム位置でこの効果を達成したい場合は、探しているものを達成できるものがないため、手動でコーディングする必要があります。

お役に立てば幸いです、頑張ってください!

于 2012-08-29T14:42:27.717 に答える