zoukankan      html  css  js  c++  java
  • 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;

    }

  • 相关阅读:
    jmeter录制
    Jmeter之逻辑控制器
    Jmeter关联
    Jmeter之HTTP请求默认值
    shell一文入门通
    Linux系统编程——基础命令总结
    前端专业方向的尽头
    锤子,技术与交互体验细节
    学习汇总 2019-12-2
    不容错过的 Babel7 知识
  • 原文地址:https://www.cnblogs.com/diweinan/p/6213935.html
Copyright © 2011-2022 走看看