UITableView 或 UIScrollView 點擊狀態欄列表回到頂部


整理來自互聯網~
這是tableView繼承的scrollView的一個屬性 scrollsToTop。
官方說明是這樣的:
// When the user taps the status bar, the scroll view beneath the touch which is closest to the status bar will be scrolled to top, but only if its `scrollsToTop` property is YES, its delegate does not return NO from `shouldScrollViewScrollToTop`, and it is not already at the top.
// On iPhone, we execute this gesture only if there's one on-screen scroll view with `scrollsToTop` == YES. If more than one is found, none will be scrolled.
@property(nonatomic) BOOL scrollsToTop; // default is YES.
 
想要實現此功能需要滿足以下條件:
1.屏幕中只有一個scrollView或tableView。
2.它的scrollsToTop屬性設置為YES,默認為YES。
 
想要禁用掉此功能將scrollsToTop屬性設置為NO即可。
 
@近日一個朋友問起,一個ViewController下,放了多個tableView時,點擊狀態欄不能回到頂部,起初以為是他把scrollsToTop設置為NO,細看之下才發現不是,原來
On iPhone, we execute this gesture only if there’s one on-screen scroll view with scrollsToTop == YES. If more than one is found, none will be scrolled.
@說的是:iOS 下 UITableView/UIScrollView 有個特性:點擊狀態欄回到頂部。如果當前 view 下有多個 scrollView,或者多個 tableView 嵌套,點擊回到頂部就無效,因為系統不知道該響應哪個,索性就全部禁用.
@解決辦法:當前顯示哪個tableView,哪個的scrollsToTop就設置為YES,其余的設置為NO;


免責聲明!

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



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