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

    }

  • 相关阅读:
    tp.c
    trace
    一致性哈希算法
    update_dctcp_alpha
    dctcp-ns2-patch
    C++ inheritance: public, private. protected ZZ
    C++ virtual inheritance ZZ
    C++ 类对象的初始化顺序 ZZ
    C++ inheritance examples
    classifier.cc-recv() [ns2.35]
  • 原文地址:https://www.cnblogs.com/diweinan/p/6213935.html
Copyright © 2020-2023  润新知