SWRevealViewController在滑动时关闭键盘 [英] SWRevealViewController dismiss keyboard on swipe

查看:167
本文介绍了SWRevealViewController在滑动时关闭键盘的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的应用中使用 SWRevealViewController ,我遇到了问题。我在场景中有一个文本字段,如果我在键盘打开时向左滑动,菜单会出现,但它不会关闭键盘。如何在左侧滑动时关闭键盘?
我试过了

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

但它不起作用,我想因为我已经在使用panGestureRecognizer revealViewcontroller ie [self.view addGestureRecognizer:self.revealViewController.panGestureRecognizer];

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

我也在使用 UITapGestureRecognizer 但它仅适用于点按而不适用于滑动。
我希望这个问题有一个非常简单的解决方案,任何人都可以帮忙吗?

I am also using UITapGestureRecognizer but it only works for tap not for swipe. I hope there is a very simple solution for this problem, Can anyone help?

谢谢,

推荐答案

我认为你需要在app委托中使用其中一个委托方法,所以可以委托方法,但你需要做下面的事情

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

不要添加任何手势

appDelegate中使用此委托
删除所有宏都以开始#if 不需要

在app appate中设置一个断点方法
下面的委托方法每次 SWRevealViewController 移动或切片..

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 ...

FrontViewController.h

  -(void)dismissKeyboard; //add this 

>

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

这篇关于SWRevealViewController在滑动时关闭键盘的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆