Skip to content
This repository has been archived by the owner on Jan 3, 2019. It is now read-only.

UIPanGestureRecognizer implementation #8

Open
hebertialmeida opened this issue Feb 28, 2014 · 11 comments
Open

UIPanGestureRecognizer implementation #8

hebertialmeida opened this issue Feb 28, 2014 · 11 comments

Comments

@hebertialmeida
Copy link
Owner

No description provided.

@xhzengAIB
Copy link
Contributor

Hi! @hebertialmeida
would you have finished?

Jack

@hebertialmeida
Copy link
Owner Author

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

@xhzengAIB
Copy link
Contributor

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

Jack

@mukyasa
Copy link

mukyasa commented Jul 28, 2014

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];



        }

    }
}

}

@xhzengAIB
Copy link
Contributor

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

Jack

@mukyasa
Copy link

mukyasa commented Oct 11, 2014

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

@xhzengAIB
Copy link
Contributor

@mukyasa

Please tell me, your project link?

Thanks

Jack

@mukyasa
Copy link

mukyasa commented Oct 12, 2014

@xhzengAIB
Copy link
Contributor

@mukyasa

Thanks !

Jack

@mukyasa
Copy link

mukyasa commented Oct 14, 2014

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

@hebertialmeida
Copy link
Owner Author

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants