ScrollView设置了ContentSize高度为0,仍然能滑动的问题
你有没有遇到过这样的情况:
对于ScrollView的不能上下滑动,设置了以下代码:
_scrollViewTitle=[[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, kWidth, TitleHeight)];
_scrollViewTitle.contentSize = CGSizeMake(_titleArray.count*btnWidth, 0);
可是....ScrollView仍然能够滑动...你一定检查了创建和设置ScrollView的代码很多遍,还是发现不了问题..哈哈,我也一样...

其实解决方法很简单: 看代码:
- (void)initcategroyScrollView{
self.automaticallyAdjustsScrollViewInsets = NO;
_scrollViewTitle = [[UIScrollView alloc]initWithFrame:CGRectMake(, , kWidth, TitleHeight)];
_scrollViewTitle.delegate = self;
_scrollViewTitle.tag = ;
_scrollViewTitle.bounces = NO;
_scrollViewTitle.backgroundColor = [UIColor greenColor];
_scrollViewTitle.showsVerticalScrollIndicator = YES;
_scrollViewTitle.showsHorizontalScrollIndicator = YES;
_scrollViewTitle.alwaysBounceVertical = NO; // 默认是NO
_scrollViewTitle.directionalLockEnabled =YES;//禁止同时左右和上下滚动
[self.view addSubview:_scrollViewTitle];
_scrollViewTitle.contentSize = CGSizeMake(_titleArray.count*btnWidth, );
for (int i = ; i < _titleArray.count; i++) {
UIButton*btn = [[UIButton alloc]initWithFrame:CGRectMake(btnWidth*i, , btnWidth, TitleHeight)];
[btn setBackgroundColor:[UIColor whiteColor]];
btn.tag =+i;
btn.enabled = NO;
[btn setTitle:_titleArray[i] forState:UIControlStateNormal];
[btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
[btn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
[_scrollViewTitle addSubview:btn];
if (i==) {
_index=+i;
[btn setTitleColor:Main_Color forState:UIControlStateNormal];
}
}
_lineView = [[UIView alloc]initWithFrame:CGRectMake(, TitleHeight-, btnWidth, )];
_lineView.tag=;
_lineView.backgroundColor = [UIColor redColor];
[_scrollViewTitle addSubview:_lineView];
}
总结:
设置代码 self.automaticallyAdjustsScrollViewInsets = NO;即可
- automaticallyAdjustsScrollViewInsets是ViewController的一个属性,指示VIewController是否需要自动调整ScrollViewInsets。
- 默认值为YES,允许ViewController自动调整ScrollViewInsets ##VC对ScrollView的调整
- 当automaticallyAdjustsScrollViewInsets值为YES时,viewController根据当前view中statusBar,navigaionTionBar,toolBar或者toolBar来自动调整scrollView的的contentInset和ContentOffset。使得scrollView的内容不会被这些Bar遮挡
其实还是不怎么懂automaticallyAdjustsScrollViewInsets和scrollView的滑动有啥关系呢???有懂的大神留言告诉我哟..很感谢...嘿嘿
ScrollView设置了ContentSize高度为0,仍然能滑动的问题的更多相关文章
- 有两种分别用<bgsound>和<embed></embed>标签,当用<embed>插入背景音乐时可以设置宽度和高度为0,隐藏播放器。
<bgsound>: <bgsound> 是用来插入背景音乐,但只适用于 ie,其参数设定不多.如下 <bgsound src="your.mid" ...
- 实现ScrollView中包含ListView,动态设置ListView的高度
ScrollView 中包含 ListView 的问题 : ScrollView和ListView会冲突,会导致ListView显示不全 <?xml version="1.0" ...
- js不需要知道图片宽高的懒加载方法(经过实际测试,不加宽高仍然是无法正常加载的,设置height:auto,height:100%,仍然显示高度为0)
js不需要知道图片宽高的懒加载方法 懒加载是如何实现的? - 简书https://www.jianshu.com/p/e86c61468285找到一个不需要知道图片宽高的懒加载方法了(经过实际测试,不 ...
- ScrollView子控件高度设置无效
ScrollView子控件高度设置无效 简述 项目中引入了第三方的下拉刷新包PullToRefreshScrollView. 由于我之前布局未考虑下拉刷新功能.后来暂时发现添加上去,发现.子控件的高度 ...
- 小程序给scroll-view设置高度,使得它能适配各种尺寸的手机
scroll-view占满整个屏幕,且scroll-view的滚动不影响到页面其他地方的滚动 在iphone6的尺寸下,scroll-view设置高度为1110rpx,就不会影响页面其他地方的滚动 但 ...
- js 获取滚动条的高度 以及 设置滚动条的高度
//设置窗口滚动条高度 function setScrollTop(top){ if(!isNaN(top))document.body.scrollTop = top; } //取窗口滚动条高度 f ...
- 设置UILabel可变高度(根据文本内容自动适应高度)
@property(nonatomic)UILabel *showLabel; // 计算文本所占高度,计算出来之后设置label的高度 // 第一个参数:字体大小,字体大小/样式影响计算字体的高 ...
- 百度ueditor上传图片时如何设置默认宽高度
百度ueditor上传图片时如何设置默认宽高度 一.总结 一句话总结:直接css或者js里面限制一下就好,可以用html全局限制一下图片的最大高度 直接css或者js里面限制一下就好,可以用html全 ...
- css浮动中避免包含元素高度为0的4种解决方法
问题:当子元素中使用了float时,如果其父元素不指定高度,其高度将为0 解决:清除(闭合)浮动元素,使其父div高度自适应 方法一:额外标签+clear:both (W3C推荐方法,兼容性较 ...
随机推荐
- php 垃圾处理机制
在php5.3版本之前, php变量的回收机制只是简单的通过计数来处理(当refcount=0时,会回收内存),但这样会出现一个问题 $a=array("str"); $a[]=& ...
- 【BZOJ 3514】Codechef MARCH14 GERALD07 加强版
题意 \(n\) 个点 \(m\) 条边的无向图,\(k\) 次询问保留图中编号在 \([l,r]\) 的边的时候图中的联通块个数.强制在线. \(n,m,k\le 2\times 10^5\) 题解 ...
- python操作mysql代码讲解(及其实用,未来测试工作主要操作数据库的方法)
pymsql pymsql是Python中操作MySQL的模块,其使用方法和MySQLdb几乎相同. 下载安装 1 pip3 install pymysql 使用操作 1.执行SQL 1 2 3 4 ...
- python+Appium自动化:各种元素定位方法
name定位 driver.find_element_by_name('飞利浦净水').click() 测试结果报错:selenium.common.exceptions.InvalidSelecto ...
- BZOJ2118 墨墨的等式[同余类最短路]
声明:关于这题的$O(mn)$尚且未深入理解,虽然之前有跟这位神仙聊过做法但并没太懂.. $O(mn\log m)$同余最短路做法: 首先不妨抽出最小的$a_i=m$,那么剩余的$a$如果可以表示出$ ...
- electron-vue [Vue warn]: Failed to resolve directive: decorator
electron-vue引入ant-desigin-vue使用ant自定义指令 v-decorator报销 <a-form-item> <a-input v-decorator=&q ...
- JavaStript基础 —— JavaStript语法
JavaStript 简介 JavaScript诞生于 1995年.当然,它的主要目的是处理以前由服务器端语言负责的一些输入验证操作. 如今,JavaStript的用途早就不再局限于简单的数据验证,而 ...
- this 的用法 为原始类型扩展方法
namespace Demo { public static class Extends { // string类型扩展ToJson方法 public static object ToJson(thi ...
- keras基于卷积网络手写数字识别
import time import keras from keras.utils import np_utils start = time.time() (x_train, y_train), (x ...
- js 密码为空显示错误
<script> var user = document.getElementById("user"); var pwd = document.getElementBy ...