Fork me on GitHub

scrollView的几个属性contentSize contentOffset contentInset

1.不能向上滑动很可能是因为contentSize的大小不对。

 scrollView的几个属性contentSize contentOffset contentInset

 

contentSizescrollview可以滚动的区域,比如frame = (0 ,0 ,320 ,480) contentSize = (320 ,960),代表你的scrollview可以上下滚动,滚动区域为frame大小的两倍。

contentOffsetscrollview当前显示区域顶点相对于frame顶点的偏移量,比如上个例子你拉到最下面,contentoffset就是(0 ,480),也就是y偏移了480

contentInsetscrollviewcontentview的顶点相对于scrollview的位置,例如你的contentInset = (0 ,100),那么你的contentview就是从scrollview(0 ,100)开始显示

 

另外UITableViewUIScrollView的子类,它们在上述属性又有所不同,tabelviewcontentsize是由它的下列方法共同实现的

- (NSInteger)numberOfSections;

- (NSInteger)numberOfRowsInSection:(NSInteger)section;

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath;

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section;

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section;

它会自动计算所有的高度和来做为它的contentsizeheight.

 

例如你在delegate方法

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

    return 100;

}

那么你的tabelviewcontentsize就是(320, 4400)

出处:http://hi.baidu.com/cuikun050959/blog/item/d6908c192fcc4a0b41341732.html

 

关于点击状态栏不回到顶部问题解决方法

@property(nonatomic) BOOL  scrollsToTop;          // default is YES. 


设置这个属性,可以让点击状态栏不回到顶部,但是如果我们需要让他回到顶部,程序又不响应操作,解决方法 

刚才上面的官方文档说了,只有当一个主控制器有一个scrollview 并把这个属性设置为yes,其他的scrollview.scrollsToTop = NO 这样才会响应这个事件,原理很简单,如果有2个scrollview,系统根本不知道你需要哪个滚动到最上面 

posted on 2012-02-10 21:32  pengyingh  阅读(19914)  评论(0编辑  收藏  举报

导航