zoukankan      html  css  js  c++  java
  • 在baseViewController 里边 隐藏键盘的操作

    - (void)j_tapDismissKeyboard

    {

        NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];

        

        UITapGestureRecognizer *singleTapGR = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(j_tapAnywhereToDismissKeyboard:)];

        

        __weak UIViewController *weakSelf = self;

        

        NSOperationQueue *mainQuene =[NSOperationQueue mainQueue];

        

        [nc addObserverForName:UIKeyboardWillShowNotification object:nil queue:mainQuene usingBlock:^(NSNotification *note) {

            

            [weakSelf.view addGestureRecognizer:singleTapGR];

        }];

        

        [nc addObserverForName:UIKeyboardWillHideNotification object:nil queue:mainQuene usingBlock:^(NSNotification *note) {

            

            [weakSelf.view removeGestureRecognizer:singleTapGR];

        }];

    }

    - (void)j_tapAnywhereToDismissKeyboard:(UIGestureRecognizer *)gestureRecognizer

    {

        [self.view endEditing:YES];

    }

    1、关闭所有actionSheet和alertView:


    - (void)closeModalView  {

           for(UIWindow* window in [UIApplication sharedApplication].Windows)    {

                for(UIView* view in window.subviews)        {          

                  [self dismissActionSheetAndAletrtViewInView:view];      

                }

          }

    }

    - (void)dismissActionSheetAndAletrtViewInView:(UIView*)view {

             if ([view isKindOfClass:[UIActionSheet class]])  {

                 UIActionSheet *actionView = (UIActionSheet *)view;

                 [actionView dismissWithClickedButtonIndex:actionView.cancelButtonIndex                      animated:NO];

          }

            else if ([view isKindOfClass:[UIAlertView class]]) {

                 UIAlertView *alertView = (UIAlertView *)view;

               [alertView dismissWithClickedButtonIndex:alertView.cancelButtonIndex                            animated:NO];

           }

           else  {

                for (UIView* subView in view.subviews) {

                    [self dismissActionSheetAndAletrtViewInView:subView];

                 }

            }

    }

    2、隐藏所有键盘:


    - (void)hideKeyBoard {

               for (UIWindow* window in [UIApplication sharedApplication].windows) {

                     for (UIView* view in window.subviews) {

                             [self dismissAllKeyBoardInView:view];

                    }

              }

    }

    -(BOOL) dismissAllKeyBoardInView:(UIView *)view {

                if([view isFirstResponder]) {

                      [view resignFirstResponder];

                      return YES;

                }

               for(UIView *subView in view.subviews) {

                    if([self dismissAllKeyBoardInView:subView]) {

                        return YES;

                 }

         }

         return NO;

    }

  • 相关阅读:
    Spring-Security (学习记录四)--配置权限过滤器,采用数据库方式获取权限
    使用IDEA将代码托管到GitHub步骤和错误解决
    Windows 10 操作系统删除Administrator登录选项
    Android的四种储存方式(SQLite、FileSystem、SDCardSystem、SharedPreferences)
    php环境之Wampserver端口修改
    JAVA8新特性——方法引用
    JAVA8新特性——Lamda表达式
    HTTP通信模拟表单提交数据
    JAVA8新特性——接口定义增强
    修改SpringBoot 默认的小叶子图标
  • 原文地址:https://www.cnblogs.com/yecong/p/6423263.html
Copyright © 2011-2022 走看看