Note that there are some explanatory texts on larger screens.

plurals
  1. POMoving UIImageView over multiple CGPoints (Array) without CAAnimations but with "Fling/Flick"
    primarykey
    data
    text
    <p>I have some images, all those images are placed on their own UIImageView. I have a NSArray that contains multiple points where i want the images to move. All images must follow eachother and it is possible that only 5 of the 10 images are on that track at the same time (User setting). Still those images must be spread evenly on the path.</p> <p>My problem is that i can make the images move, but i cannot give a "fling or flick" movement like a UIScrollView and UITableView has. (Move by UIPanGesture and on release use the remaining speed to calculate how long the images should keep moving while slowing down until they can stop).</p> <p>My UIImageViews jump to the last place instead of moving from one point to another. I already tried using a default Animation, but then the UIImageViews leaving and entering the screen give me a problem.</p> <p>This is the code i created to test just this part (movement)</p> <pre><code> - (void) move: (int) direction{ switch (direction) { case MOVEMENT_LEFT: { if ((currentLocation -1) &lt;= startpoint){ currentLocation = endpoint; } else { currentLocation--; } } break; case MOVEMENT_RIGHT: { if ((currentLocation +1) &gt;= 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 &lt; 0 &amp;&amp; velocity.y &lt; 0) || (velocity.x &lt; 0 &amp;&amp; velocity.y &gt; 0) || (velocity.x &lt; 0 &amp;&amp; velocity.y == 0) || (velocity.x == 0 &amp;&amp; velocity.y &lt; 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 &gt; 0 &amp;&amp; velocity.y &gt; 0) || (velocity.x &gt; 0 &amp;&amp; velocity.y &lt; 0) || (velocity.x &gt; 0 &amp;&amp; velocity.y == 0) || (velocity.x == 0 &amp;&amp; velocity.y &gt; 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 &gt; 1250){ NSLog(@"Fling Movement Event"); //int sleeper = 0; if (gestureDirection == MOVEMENT_LEFT){ for (int i = speed; i &gt; 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 &gt; 0; i--){ [image removeFromSuperview]; [self move:MOVEMENT_RIGHT]; sleep(.05); [[self view] addSubview:image]; //sleeper = sleeper + 100; //sleep(sleeper); } } } else { NSLog(@"Normal Movement Event"); } } } </code></pre> <p>What i'm trying to achieve is: UIImageViews that move over a SINUS-WAVE from left to right or back (depending on the users touches) and images that leave left will be replaced with the next image in an Array on the right, also backwards..</p> <p>So: [Image F] [Image A] [Image B] [Image C] [Image D] User moves his finger to the right... And: [Image G] [Image F] [Image A] [Image B] [Image C] And With a fling it would step forward more, but still displaying all Images on the go..</p> <p>Hope somebody can help..</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload