iOS關於UIScrollView滾動置頂的解決方案

① 適用於UIScrollView

    CGPoint off = self.tableView.contentOffset;
    off.y = 0 - self.tableView.contentInset.top;
    [self.tableView setContentOffset:off animated:YES];

    //或者
 [self.tableView setContentOffset:CGPointZero animated:NO];

② 如果①無效 則再試試

[self.tableView scrollRectToVisible:CGRectMake(0, 0, 1 , 1) animated:YES];

③ 如果以上無效

   NSIndexPath* indexPath = [NSIndexPath indexPathForRow:0 inSection:0];
   [self.tableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionBottom animated:YES];

④ 呵呵😑


[self.tableView scrollToNearestSelectedRowAtScrollPosition:UITableViewScrollPositionTop animated:YES];

/** 滾動到頂部 */
[self.tableView setScrollsToTop:YES];
    
/** 讓指定區域滾動到可視區域*/
[self.tableView scrollRectToVisible:CGRectMake(0, 0, 1, 1) animated:YES];
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章