• 让UIScrollView、UITableView的滚动条一直显示


    先用xcode5.1.1或更低版本创建一个Category,如图:

    然后拷贝以下代码到刚创建的UIImageView+ForScrollView.m文件中:

    - (void) setAlpha:(float)alpha {
        
        if (self.superview.tag == noDisableVerticalScrollTag) {
            if (alpha == 0 && self.autoresizingMask == UIViewAutoresizingFlexibleLeftMargin) {
                if (self.frame.size.width < 10 && self.frame.size.height > self.frame.size.width) {
                    UIScrollView *sc = (UIScrollView*)self.superview;
                    if (sc.frame.size.height < sc.contentSize.height) {
                        return;
                    }
                }
            }
        }
        
        if (self.superview.tag == noDisableHorizontalScrollTag) {
            if (alpha == 0 && self.autoresizingMask == UIViewAutoresizingFlexibleTopMargin) {
                if (self.frame.size.height < 10 && self.frame.size.height < self.frame.size.width) {
                    UIScrollView *sc = (UIScrollView*)self.superview;
                    if (sc.frame.size.width < sc.contentSize.width) {
                        return;
                    }
                }
            }
        }
        
        [super setAlpha:alpha];
    }

    在.pch中定义这两个值:

    #define noDisableVerticalScrollTag 836913
    #define noDisableHorizontalScrollTag 836914

    然后在你所用到UIScrollViewUITableView的视图控制器中:

    #import "UIImageView+ForScrollView.h"

    设置UIScrollViewUITableView:

        UIScrollView *scrollview = [[UIScrollView alloc]initWithFrame:self.view.bounds];
        scrollview.contentSize = CGSizeMake(320, 960);
        scrollview.tag = noDisableVerticalScrollTag;
        [scrollview flashScrollIndicators];
        [self.view addSubview:scrollview];
        
        //---
        _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 66, 320, 480)];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.showsHorizontalScrollIndicator = YES;
        _tableView.tag = noDisableVerticalScrollTag;
        [_tableView flashScrollIndicators];
        [self.view addSubview:_tableView];

    如此即可让UIScrollView、UITableView的滚动条一直显示。

    
    
  • 相关阅读:
    Linux下安装Tomcat服务器和部署Web应用
    两个有序链表的合并
    一个时间效率为O(n)的排序算法
    五种常用的Web安全认证方式
    接口认证方式
    curl 命令详解~~
    高德地图、腾讯地图、谷歌中国区地图与百度地图坐标系
    CentOS 7 yum 安装与配置 JDK
    PHP调用Google Translate API接口
    关联了微信开放平台的小程序,某些情况无法获取到unionId
  • 原文地址:https://www.cnblogs.com/hw140430/p/4106269.html
Copyright © 2020-2023  润新知