Note that there are some explanatory texts on larger screens.

plurals
  1. POframe by frame animation with UIGestureRecognizer
    primarykey
    data
    text
    <p>I would like to show an animation with images of an object rotating. I have an <code>NSArray</code> with frames of the object and I would like to display them frame by frame with the property of <code>UIImageView</code> <code>animationImages</code>. </p> <p>The problem is that I would like to control the animation with <code>UISwipeGestureRecognizer</code> (Right and Left). And depending on the speed of the gesture the object should rotate faster or slower. I think is not possible because the gesture it is called just once and not continuously.</p> <p>(NOTE: this is my first question in StackOverflow)</p> <p>Thank you in advance</p> <p>EDIT: I just post my solution. Maybe it can be useful for anybody. I think it's useful.</p> <p><strong>Firstly:</strong> add gesture to the view.</p> <pre><code>self.recognizer = [[UISwipeGestureRecognizer alloc] init]; self.recognizer.cancelsTouchesInView=NO; [self.view addGestureRecognizer:self.recognizer]; </code></pre> <p><strong>Secondly:</strong> in tocuhMoved method I display the frame that I need depending of the direction of the previous touch. It is called by the event of the user.</p> <pre><code>- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{ NSInteger image= [self.animationView.animationImages indexOfObject:self.animationView.image]; UITouch *touch = [touches anyObject]; NSLog(@"Touch moved with index:%i", image); if ((positionTouch.x&lt;[touch locationInView:self.animationView].x)) { if (image==24) { self.animationView.image=[self.animationView.animationImages objectAtIndex:0]; } else{ self.animationView.image=[self.animationView.animationImages objectAtIndex:image+1]; } } else if((positionTouch.x&gt;[touch locationInView:self.animationView].x)){ if (image==0) { self.animationView.image=[self.animationView.animationImages objectAtIndex:24]; } else{ self.animationView.image=[self.animationView.animationImages objectAtIndex:image-1]; } } positionTouch= [touch locationInView:self.animationView]; } </code></pre> <p>Don't forget <code>&lt;UIGestureRecognizerDelegate&gt;</code></p> <p>with this method, I fill the array of frames...</p> <pre><code>-(void)addPictures{ NSMutableArray* mArray=[[NSMutableArray alloc]initWithCapacity:25]; for (int i=0; i&lt;25; i++) { [mArray insertObject:[UIImage imageNamed:[NSString stringWithFormat:@"Picture %i.jpg", i+1]] atIndex:i]; } self.animationView.image=[mArray objectAtIndex:0]; self.animationView.animationImages=mArray; [self.view addSubview:self.animationView]; } </code></pre>
    singulars
    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