多个scrollView时点击statusbar失效的解决办法

当viewController中只有一个scrollView时,点击statusBar,该scrollView就会滚动到顶部,但当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时如果发现有多个scrollView时就不会有滚动效果了。

解决办法很简单,把需要有滚动效果的scrollView的scrollsToTop属性设为YES,其他的设为NO,也就是说同一时间内只能让一个scrollView的scrollsToTop属性为YES。

你可能感兴趣的:(多个scrollView时点击statusbar失效的解决办法)