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];


免責聲明!

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



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