1.不能向上滑動很可能是因為contentSize的大小不對。
scrollView的幾個屬性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)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; 它會自動計算所有的高度和來做為它的contentsize的height.
例如你在delegate方法 - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return 100; } 那么你的tabelview的contentsize就是(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,系統根本不知道你需要哪個滾動到最上面