• iOS开发 自定义窗口 以及 点击scrollView置顶


    static UIWindow *topWindow_;

    static UIScrollView *scrollView_;

    /**

     * 显示顶部窗口

     */

    + (void)show

    {

      dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.25 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{

        topWindow_ = [[UIWindow alloc] init];

        topWindow_.windowLevel = UIWindowLevelAlert;

        topWindow_.frame = CGRectMake(60, 0, fView_Width(kWindow), 20);

        topWindow_.backgroundColor = [UIColor clearColor];

        topWindow_.hidden = NO;

        [topWindow_ addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(topWindowClick)]];

      });

    }

    /**

     * 监听顶部窗口点击

     */

    + (void)topWindowClick

    {

      UIWindow *keyWindow = [UIApplication sharedApplication].keyWindow;

      [self searchAllScrollViewsInView:keyWindow];

    }

    /**

     * 找到参数view中所有的UIScrollView

     */

    + (void)searchAllScrollViewsInView:(UIView *)view

    {

      // 递归遍历所有的子控件

      for (UIView *subview in view.subviews) {

        [self searchAllScrollViewsInView:subview];

      }

      

      // 判断子控件类型(如果不是UIScrollView,直接返回)

      if (![view isKindOfClass:[UIScrollView class]]) return;

      

      // 找到了UIScrollView

      UIScrollView *scrollView = (UIScrollView *)view;

        

      // 让UIScrollView滚动到最前面

      // 让CGRectMake(0, 0, 1, 1)这个矩形框完全显示在scrollView的frame框中

    //  [scrollView scrollRectToVisible:CGRectMake(0, 0, 1, 1) animated:YES];

      if (scrollView == scrollView_) {

        [scrollView setContentOffset:CGPointMake(scrollView.contentOffset.x, -scrollView.contentInset.top) animated:YES];

      }

    }

    + (void)configScrollView:(UIScrollView *)scrollView {

      scrollView_ = scrollView;

    }

  • 相关阅读:
    2.2 列表推导和生成器表达式
    1.2 如何使用特殊方法
    Selenium安装方法
    Python中Selenium的使用方法
    BeautifulSoup4的使用方法
    (转)Python中sort和sorted的区别和使用方法
    (转)Python中random模块的几个常用函数
    PR中我的常用快捷键
    二、交互式运行环境——REPL
    一、Node.js概述
  • 原文地址:https://www.cnblogs.com/diweinan/p/6213935.html
Copyright © 2020-2023  润新知