HAPaperViewController icon indicating copy to clipboard operation
HAPaperViewController copied to clipboard

UIPanGestureRecognizer implementation

Open hebertialmeida opened this issue 10 years ago • 11 comments

hebertialmeida avatar Feb 28 '14 02:02 hebertialmeida

Hi! @hebertialmeida would you have finished?

Jack

xhzengAIB avatar Apr 20 '14 15:04 xhzengAIB

Sorry @xhzengAIB I'm working on another project because I'm going to the WWDC and I need finish this.

hebertialmeida avatar Apr 21 '14 02:04 hebertialmeida

Hi! @hebertialmeida That's ok, you finish your project! Because WWDC is very great.

Jack

xhzengAIB avatar Apr 21 '14 02:04 xhzengAIB

Hi! @hebertialmeida

I am trying to replicate the UIPanGestureRecognizer,

The above code is not working 100%,It shows a lag while progress,but it is working .

Can you please tell me where i am wrong,in calculating progress and offset,If u have implemented

Thank You.

  • (void)oneFingerGesture:(UIPanGestureRecognizer *)sender { static UIPanGestureRecognizerDirection direction = UIPanGestureRecognizerDirectionUndefined; CGPoint point; CGPoint tempvelocity;

    CGFloat magnitude; if (sender.state == UIGestureRecognizerStateEnded) { [self endInteractionWithSuccess:YES];

    } else if (sender.state == UIGestureRecognizerStateCancelled) { [self endInteractionWithSuccess:NO]; } else if (sender.numberOfTouches == 1 ){ NSLog(@"On finger gesture");

         // the main touch point
    CGPoint point1;     // location of touch #1
    CGFloat distance = 0.0;   // computed distance between both touches
    
    // return the locations of each gesture’s touches in the local coordinate system of a given view
    
     point1 = [sender locationOfTouch:0 inView:sender.view];
    
    
    
    
    // get the main touch point
    point = [sender locationInView:sender.view];
    
    if (sender.state == UIGestureRecognizerStateBegan)
    {
         tempvelocity = [sender velocityInView:sender.view];
    
        BOOL isVerticalGesture = fabs(tempvelocity.y) > fabs(tempvelocity.x);
    
        if (isVerticalGesture) {
            if (tempvelocity.y > 0) {
                direction = UIPanGestureRecognizerDirectionDown;
                if (!self.hasActiveInteraction)
                {
                    //self.initialPinchDistance = distance;
                    self.initialPinchPoint = point;
                    self.hasActiveInteraction = YES;    // the transition is in active motion
                    [self.delegate interactionBeganAtPoint:point];
                }
    
            } else {
                direction = UIPanGestureRecognizerDirectionUp;
                if (!self.hasActiveInteraction)
                {
                    //self.initialPinchDistance = distance;
                    self.initialPinchPoint = point;
                    self.hasActiveInteraction = YES;    // the transition is in active motion
                    [self.delegate interactionBeganAtPoint:point];
                }
            }
        }
    
    
    
    }
    
    if (self.hasActiveInteraction){
    
        if (sender.state == UIGestureRecognizerStateChanged){
    
    
    
            CGPoint translation = [sender translationInView:sender.view];
    
              magnitude = sqrt((translation.x * translation.x) + (translation.y * translation.y));
    
            self.initialPinchDistance = magnitude;
    
            CGFloat delta = magnitude - self.initialPinchDistance;
    
            CGFloat offsetX = point.x - self.initialPinchPoint.x;
    
            CGFloat offsetY = (point.y - self.initialPinchPoint.y)+delta/M_PI;
    
    
            UIOffset offsetToUse = UIOffsetMake(offsetX, offsetY);
    
            [sender setTranslation:CGPointMake(0, 0) inView:sender.view];//no change
    

// CGFloat distanceDelta =magnitude; // if (self.navigationOperation == UINavigationControllerOperationPop) // { // distanceDelta = -distanceDelta; // } // CGFloat progress = MAX(MIN(((magnitude + (tempvelocity.y+tempvelocity.x) * M_PI) / 250), 1.0), 0.0);

            [self updateWithProgress:magnitude andOffset:offsetToUse];



        }

    }
}

}

mukyasa avatar Jul 28 '14 14:07 mukyasa

Hi! @mukyasa
You can try pull request to this open source?

Jack

xhzengAIB avatar Aug 10 '14 13:08 xhzengAIB

I will upload this project with my version of PanGesture soon(With small Performance improvement)

mukyasa avatar Oct 11 '14 08:10 mukyasa

@mukyasa

Please tell me, your project link?

Thanks

Jack

xhzengAIB avatar Oct 11 '14 16:10 xhzengAIB

https://github.com/mukyasa/MMPaper

mukyasa avatar Oct 12 '14 07:10 mukyasa

@mukyasa

Thanks !

Jack

xhzengAIB avatar Oct 13 '14 02:10 xhzengAIB

Hey Jack check it now,I have made some tweaks,

Also heberti please check it out the zoom pan gesture in my version,please give some suggestion so that we can improve it.

Cheers

mukyasa avatar Oct 14 '14 05:10 mukyasa

Hi @mukyasa I will check it! And when do you finish it, please make a pull request to this repo if possible...

hebertialmeida avatar Oct 14 '14 22:10 hebertialmeida