怎样tableview设置偏移量UIScrollView每次移动的偏移量

主题 : UIScrollView偏移了20个像素
级别: 新手上路
UID: 320694
可可豆: 38 CB
威望: 37 点
在线时间: 96(时)
发自: Web Page
来源于&&分类
UIScrollView偏移了20个像素&&&
在scrollview中 动态添加了一个UILabel 标签,高度跟scrollview一致,但是运行后scrollview偏移了二十个像素。 在网上找了两个方法: 1)if ([[UIDevice currentDevice] systemVersion].floatValue&=7.0) {self.automaticallyAdjustsScrollViewInsets = NO;} 2)- (void)viewWillLayoutSubviews{    [super viewWillLayoutSubviews];    if (IOS_7_OR_LATER) {        [self.scrollView setContentInset:UIEdgeInsetsZero];    }}都不合适。不知道有没有遇到过类似问题的朋友,希望能给解决下,最好给出出现这个问题的原因。谢谢!
级别: 新手上路
UID: 320694
可可豆: 38 CB
威望: 37 点
在线时间: 96(时)
发自: Web Page
在网上又搜了下资料,基本说的都是automaticallyAdjustsScrollViewInsets的原因,为什么我加了之后不起作用呢?
级别: 新手上路
UID: 320694
可可豆: 38 CB
威望: 37 点
在线时间: 96(时)
发自: Web Page
倒腾了一天终于解决了,具体思路我参考的是: 中作者提到的第二种。
级别: 侠客
可可豆: 370 CB
威望: 337 点
在线时间: 1633(时)
发自: Web Page
用不着代码。直接加一个隐藏的1像素view放在scrollView的底部就行了。
级别: 新手上路
UID: 213617
可可豆: 145 CB
威望: 110 点
在线时间: 1220(时)
发自: Web Page
在对应的ViewController中加这个试试:&&&&self.edgesForExtendedLayout=UIRectEdgeN&&&&self.extendedLayoutIncludesOpaqueBars=NO;&&&&self.automaticallyAdjustsScrollViewInsets=NO;
没个性,不签名
级别: 新手上路
UID: 320694
可可豆: 38 CB
威望: 37 点
在线时间: 96(时)
发自: Web Page
回 3楼(l0ve_m00n) 的帖子
我就是这么做的
关注本帖(如果有新回复会站内信通知您)
苹果公司现任CEO是谁?2字 正确答案:库克
发帖、回帖都会得到可观的积分奖励。
按"Ctrl+Enter"直接提交
关注CocoaChina
关注微信 每日推荐
扫一扫 浏览移动版&&国之画&&&& &&&&&&
&& &&&&&&&&&&&&&&&&&&&&
鲁ICP备号-4
打开技术之扣,分享程序人生!iOS 关于滚动视图contentSize、contentOffset、contentInset 的整理
iOS 关于滚动视图contentSize、contentOffset、contentInset 的整理
contentSize 是scrollview可以滚动的区域,比如frame = (0 ,0 ,320 ,480) contentSize = (320 ,960),代表你的scrollview可以上下滚动,滚动区域为frame大小的两倍。
contentOffset 是scrollview当前显示区域顶点相对于frame顶点的偏移量,比如上个例子你拉到最下面,contentoffset就是(0 ,480),也就是y偏移了480
contentInset 是scrollview的contentview的顶点相对于scrollview的位置,例如你的contentInset = (0 ,100),那么你的contentview就是从scrollview的(0 ,100)开始显示
另外UITableView是UIScrollView的子类,它们在上述属性又有所不同,tabelview的contentsize是由它的下列方法共同实现的
- (NSInteger)numberOfS
- (NSInteger)numberOfRowsInSection:(NSInteger)
- (CGFloat)tableView:(UITableView )tableView heightForRowAtIndexPath:(NSIndexPath )indexP
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)
它会自动计算所有的高度和来做为它的contentsize的height.
例如你在delegate方法
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return 100;
那么你的tabelview的contentsize就是(320, 4400)
(window.slotbydup=window.slotbydup || []).push({
id: '2467140',
container: s,
size: '1000,90',
display: 'inlay-fix'
(window.slotbydup=window.slotbydup || []).push({
id: '2467141',
container: s,
size: '1000,90',
display: 'inlay-fix'
(window.slotbydup=window.slotbydup || []).push({
id: '2467142',
container: s,
size: '1000,90',
display: 'inlay-fix'
(window.slotbydup=window.slotbydup || []).push({
id: '2467143',
container: s,
size: '1000,90',
display: 'inlay-fix'
(window.slotbydup=window.slotbydup || []).push({
id: '2467148',
container: s,
size: '1000,90',
display: 'inlay-fix'4726人阅读
iphone基本应用(39)
基础知识(12)
一个scrollerview(红色,0,64,320,568-64-44)放了2个view,一个blueview,(0,0,320.568-64-44)一个yellowview,(320,0,320,568-64-44),滑动这2个view时,都会向下移动64高度,点击导航栏上的按钮则不会出现向下移动,这是因为ios7适配问题。
解决办法:
参考/zcw-ios/articles/3340197.html
参考知识库
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:179584次
积分:1584
积分:1584
排名:千里之外
原创:11篇
转载:46篇
(1)(1)(2)(1)(1)(10)(1)(11)(22)(2)(5)

我要回帖

更多关于 tableview设置偏移量 的文章

 

随机推荐