代码改变世界

iOS UITableView中点击状态栏无法回滚到顶部

2016-07-24 21:13  jiangys  阅读(1464)  评论(0编辑  收藏  举报

// 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. 


设置这个属性,可以让点击状态栏不回到顶部,但是如果我们需要让他回到顶部,程序又不响应操作,解决方法 

刚才上面的官方文档说了,只有当一个主控制器有一个scrollview 并把这个属性设置为yes,其他的scrollview.scrollsToTop = NO 这样才会响应这个事件,原理很简单,如果有2个scrollview,系统根本不知道你需要哪个滚动到最上面.

 

但是

我的页面上确实只有一个UITableView,当时我就纳闷了。

但是仔细想想可能页面中还有其他的控件包含了scrollview。

scrollview  tableview 、collectionview webView都是含有scrollview 的。

我的页面中就是应用一个UIWebView导致点击顶部状态栏无法正常返回的。

 

经典案例,第三方图片滚动使用比较多的如:SDCycleScrollView

使用了SDCycleScrollView之后,回到顶部就失效了。

解决方法:

修改源代码,在 UICollectionView *mainView 创始化时,加上:

mainView.scrollsToTop = NO; // 不使用这句话,会导致回到顶部失效