Resolved Reuse UISwipeGestureRecognizer in multiple views

Discussion in 'iOS Programming' started by Tex-Twil, Jun 29, 2011.

  1. Tex-Twil, Jun 29, 2011
    Last edited: Jul 3, 2011

    Tex-Twil macrumors 68020

    Tex-Twil

    Joined:
    May 28, 2008
    Location:
    Europe
    #1
    Hi,
    I have an app with 3 views each having a view controller. I would like to navigate through the view using swipes but I cannot get it work. I think something is wrong with assigning the same UISwipeGestureRecognizer to all of my views.

    In my app delegate, I create the 3 controllers:

    Code:
    ViewControllerA *vcA = [[ViewControllerA alloc] initWithNibName:....];
    ViewControllerA *vcB = [[ViewControllerB alloc] initWithNibName:....];
    ViewControllerA *vcC = [[ViewControllerC alloc] initWithNibName:....];
    
    Then I create the recognizer which monitors swipes from right to left :

    Code:
    UISwipeGestureRecognizer * recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeFrom:)];
    recognizer.direction = UISwipeGestureRecognizerDirectionLeft; 
    
    Then I assign it to all of my views:
    Code:
    [vcA.view addGestureRecognizer:recognizer];
    [vcB.view addGestureRecognizer:recognizer];
    [vcC.view addGestureRecognizer:recognizer];
    at this point the "handleSwipeFrom" is not called at all. If I assign the same recognizer only to one view (the 1st one), it is called and works fine.


    What am I doing wrong ?

    thanks,
    Tex
     
  2. jiminaus macrumors 65816

    jiminaus

    Joined:
    Dec 16, 2010
    Location:
    Sydney
    #2
    I think assigning the same UISwipeGestureRecognizer object to all three view.

    Try creating 3 UISwipeGestureRecognizer objects and assign one to each of the views.
     
  3. Tex-Twil thread starter macrumors 68020

    Tex-Twil

    Joined:
    May 28, 2008
    Location:
    Europe
    #3
    ok I will try that.

    Btw, what I'm trying to achieve is to have a UINavigationController without the navigation bar and navigate through the views using swipes. Is this ok to have such a UI or am I doing something not conform to the guidelines ?

    cheers
     
  4. jnoxx macrumors 65816

    jnoxx

    Joined:
    Dec 29, 2010
    Location:
    Aartselaar // Antwerp // Belgium
    #4
    I do it too, with for example an UISegment at the top. Where u can click, and it will create a new controller stack on each segment. And u can swipe through the segments (other controllers).
    I just recreate them in each. or u could make a delegate, and make it conform to it.
     
  5. Tex-Twil thread starter macrumors 68020

    Tex-Twil

    Joined:
    May 28, 2008
    Location:
    Europe
    #5
    ok cool.

    I'll post back if the jiminaus' post is the solution.
     
  6. North Bronson macrumors 6502

    Joined:
    Oct 31, 2007
    Location:
    San José
    #6
    Is this application going to be published on the store?

    What happens when you turn on VoiceOver? How do blind users interact with your application when swipes are disabled (or reimplimented by the Apple VoiceOver API)?
     
  7. Tex-Twil thread starter macrumors 68020

    Tex-Twil

    Joined:
    May 28, 2008
    Location:
    Europe
    #7
    ok that worked.

    yes

    I'm not sure to understand.
     

Share This Page