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

// 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; // 不使用这句话,会导致回到顶部失效

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值