美文网首页技术笔记
[IOS]实现全局关闭所有键盘,actionSheet和aler

[IOS]实现全局关闭所有键盘,actionSheet和aler

作者: o本是后山人o偶作前堂客o | 来源:发表于2016-11-30 11:06 被阅读48次

    http://www.07net01.com/program/62525.html   原文地址.    为防止链接失效.  手动 收藏 代码.

    隐藏所有键盘:(使用过)

    - (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;

    }

    关闭所有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];

    }

    }

    }

    相关文章

      网友评论

        本文标题:[IOS]实现全局关闭所有键盘,actionSheet和aler

        本文链接:https://www.haomeiwen.com/subject/uecwlttx.html