iosswrevealviewcontroller

SWRevealViewController dismiss keyboard on swipe


I am using SWRevealViewController in my app and I am having a problem. I have a textfield in a scene, if I swipe left when the keyboard is open, the menu appears but it does not dismiss the keyboard. How do I dismiss keyboard on left swipe?

I have tried

UISwipeGestureRecognizer *swipe = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(dismissKeyboard)];
swipe.direction = UISwipeGestureRecognizerDirectionLeft;
[self.view addGestureRecognizer:swipeRecognizer];

-(void)dismissKeyboard
{
    [self.textField resignFirstResponder];
}

but it does not work, I think because I am already using a panGestureRecognizer for revealViewcontroller i.e. [self.view addGestureRecognizer:self.revealViewController.panGestureRecognizer];

I am also using UITapGestureRecognizer but it only works for tap not for swipe.


Solution

  • i think u need to use one of the delegate method in the app delegate there are so may delegate methods are there but u need do somthing like below

    dont add any gestures

    use this delegate in the appDelegate delete all the macros begins with #if don`t need that

    put a break-point in app delegate to this method below delegate method celled each time SWRevealViewController moved or sliced ..

    - (void)revealController:(SWRevealViewController *)revealController didMoveToPosition:(FrontViewPosition)position
    {
       // NSLog( @"%@: %@", NSStringFromSelector(_cmd), [self stringFromFrontViewPosition:position]);
       if(position == FrontViewPositionRight) //check the where to move 
       {
          UINavigationController *viewController = revealController.frontViewController;
    
         if([viewController.visibleViewController isKindOfClass:[FrontViewController class]])
           {
             [(FrontViewController *)viewController.visibleViewController dismissKeyboard]; //where this is the method declared in the FrontViewController.h file
          }
    
       }
    }
    

    there is one warning still it works put break point and check hope this helps u ...

    in FrontViewController.h

      -(void)dismissKeyboard; //add this 
    

    in the FrontViewController.m

     -(void)dismissKeyboard
     {
          if([self.textField isFirstResponder]) //check
             [self.textField resignFirstResponder];
     }