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,系統根本不知道你需要哪個滾動到最上面 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM