Detecting how much the user panned

Discussion in 'iOS Programming' started by erdinc27, Mar 3, 2016.

  1. erdinc27 macrumors regular

    Joined:
    Jul 20, 2011
    #1
    i want to open a left menu in the application that i develop. I can do it with a button but now the customer wants the left menu to be opened as much as the user panned the content view. For example the user panned content view 50 pix then i should open the left menu 50 pix. After a certain distance for example half of the content view's width i will open the left menu automatically. So i just want to know how much the user detected. I use such a code but it returns always 1 and 0
    Code:
    -(void)viewPanned:(UIPanGestureRecognizer *)sender {
       
       
        CGPoint rect = [sender translationInView:self.rightView];
       
        float currentX = rect.x;
       
        NSLog(@"View Panned %f", currentX - self.previousX);
       
        self.previousX = currentX;
    }
     
  2. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
  3. erdinc27 thread starter macrumors regular

    Joined:
    Jul 20, 2011
    #3
    I declared it in .h file and in viewDidLoad equalized to 0

    Code:
    @property (nonatomic, assign) float previousX;
     
  4. AxoNeuron macrumors 65816

    AxoNeuron

    Joined:
    Apr 22, 2012
    Location:
    The Left Coast
    #4
    What type of numbers do you get directly from the translationInView method? I would log those numbers out to the console and let us know what numbers you see.

    By the way, you can also use the method 'locationInView' with self.view to get the coordinates IN the view. That way you know where in the view they are panning.
     
  5. erdinc27 thread starter macrumors regular

    Joined:
    Jul 20, 2011
    #5
    To be more clear i will write from start. SideBarbnbAnimation class was used in the project that i work on now. Customer wants the left menu to be opened by dragging main view also. Now it is opened only by a button. So i want to open the menu how much the user drags the main view. How it can be done ? May be i am on the wrong way by asking panning etc
     
  6. AxoNeuron macrumors 65816

    AxoNeuron

    Joined:
    Apr 22, 2012
    Location:
    The Left Coast
    #6
    You can use UIView.animateWithDuration to change the X position of the sidebar's frame. Or you can use Core Animation, I've never really found many differences between the two performance-wise (I suspect the UIView animation methods are just another way of using CA but I'm not sure).

    Depending on the X position of the users finger, you would tie the X position of the sidebar to the X position of their finger. If their finger goes too far, you might even put in a nice little snap-back animation instead of just abruptly stopping the sidebar pullout.

    As far as the actual problem you are having, please make sure to read my previous post.
     

Share This Page