當(dāng)viewController中只有一個scrollView時,點擊statusBar,該scrollView就會滾動到頂部,但當(dāng)viewController中有多個scrollView時,這個功能就失效了。
為什么呢?UIScrollView有個屬性 ,叫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 ?__TVOS_PROHIBITED;?// default is YES.
可以看到,點擊statusBar時如果發(fā)現(xiàn)有多個scrollView時就不會有滾動效果了。
解決辦法很簡單,把需要有滾動效果的scrollView的scrollsToTop屬性設(shè)為YES,其他的設(shè)為NO,也就是說同一時間內(nèi)只能讓一個scrollView的scrollsToTop屬性為YES。