Search code examples
objective-ciosipadeasingrotator

Animating frame Images with ease effect on iPad


Let me show you example (360 Deg 3D Object Rotator):
Demo: http://activeden.net/item/interactive-renders-360-deg-3d-object-rotator/39718?ref=mixDesign

enter image description here
As you see, there is a camera 3D rotating on mouse event. Actually, it is a collection of images (frames) animating frame by frame depending on mouse event.

I want to implement this animation with objective - c using swipe gesture (or maybe I should use another gesture?). So that I can make rotation by my finger, to the left, to the right (I want animation with smooth ease effect, depending on swipe speed velocity).

Note: I have ready images for each frame.

Sample codes, online tutorials doing this will really help me.

! Should I use some external graphics library, in order to keep performance? I have hundreds of images (PNG), each with size of 300kb

Thank you in advance, I really need your help!


Solution

  • I don't think you should use swipe gesture here. I recommend you LongPressGesture with short minimumPressDuration.

    Let me show example code:

    longPress = [ [UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handleLongPressGesture:)] 
    longPress.delegate = self;
    longPress.minimumPressDuration = 0.05;
    [viewWithImage addGestureRecognizer:longPress];
    
    
    float startX; 
    float displacement = 0;
    -(IBAction)handleLongPressGesture:(UILongPressGestureRecognizer *)sender
    {   
    
    float nowX;
        if ( sender.state == UIGestureRecognizerStateBegan ) 
        {
            startX = [sender locationInView:viewWithImage].x;
        }
        if ( sender.state == UIGestureRecognizerStateEnded || sender.state == UIGestureRecognizerStateCancelled)
        {
           ... do something at end ... 
        }
    nowX = [sender locationInView:mainWidgetView].x;
    displacement = nowX - startX; 
    
      // set right rotation with displacement value
      [self rotateImageWith:displacement];
    }