无法在iOS7上使用scrollsToTop

无法在iOS7上使用scrollsToTop

本文介绍了无法在iOS7上使用scrollsToTop的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的目标是在我的最新应用中使用iOS7,点击状态栏似乎无法将tableView或collectionView滚动到顶部。

I'm targeting iOS7 in my latest app, and tapping on the status bar doesn't seem to scroll a tableView or collectionView to the top.

我'设置 self.tableView.scrollsToTop = true 但仍然没有任何反应。

I've set self.tableView.scrollsToTop = true and still nothing happens.

我知道Apple显着改变了状态栏在iOS7中,但这些更改是否会破坏 scrollsToTop 功能?

I know Apple significantly changed the status bar in iOS7, but did those changes break the scrollsToTop functionality?

更新

为了回应其中一个答案中的评论,我测试了以确保我的集合视图确实是屏幕上唯一的scrollView,它是:

In response to a comment in one of the answers, I tested to ensure that my collection view was indeed the only scrollView on the screen, and it was:

(lldb) po [self.view recursiveDescription]
<UIView: 0x1092ddf0; frame = (0 0; 320 568); autoresize = W+H; layer = <CALayer: 0x109357e0>>
   | <UICollectionView: 0x11351800; frame = (0 0; 320 568); clipsToBounds = YES; opaque = NO; autoresize = W+H; gestureRecognizers = <NSArray: 0x10966080>; layer = <CALayer: 0x109623a0>; contentOffset: {0, -64}> collection view layout: <UICollectionViewFlowLayout: 0x10940a70>
   |    | <UIImageView: 0x10965fa0; frame = (0 564.5; 320 3.5); alpha = 0; opaque = NO; autoresize = TM; userInteractionEnabled = NO; layer = <CALayer: 0x10965ee0>> - (null)
   |    | <UIImageView: 0x10948f60; frame = (316.5 561; 3.5 7); alpha = 0; opaque = NO; autoresize = LM; userInteractionEnabled = NO; layer = <CALayer: 0x10966030>> - (null)

更新#2

不确定是否重要,但我使用的是标准的iOS7 NavigationController,其中navigationBar是透明的,并且当我们在下面滚动时将模糊应用到我的集合/ tableViews。

Not sure if it matters, but I'm using a standard iOS7 NavigationController where the navigationBar is transparent and applies a blur to my collection/tableViews as they scroll underneath.

更新#3

想出来。结果我做了在屏幕上有多个scrollView。我的应用程序在应用程序的主要部分下面有一个左抽屉菜单,该菜单有一个tableView用于选项。我只需设置 self.menuTable.scrollsToTop = false ,一切都在应用程序的其余部分按预期工作。没有必要实现scrollView Delegate方法或任何东西。

Figured it out. Turns out I did have more than one scrollView on the screen. My app has a left drawer menu underneath the main part of the app, and that menu has a tableView for the options. I simply set self.menuTable.scrollsToTop = false and everything worked as expected throughout the rest of the app. Didn't have to implement the scrollView Delegate methods or anything.

推荐答案

你有多个滚动视图/表视图/屏幕上的集合视图?如果是这样,只有其中一个可以设置为 YES ,否则iOS7不会将其中任何一个滚动到顶部。

Do you have more than one scroll view/table view/collection view on screen? If so, only one of them can have scrollsToTop set to YES, otherwise iOS7 will not scroll any of them to the top.

您还可以实现UIScrollViewDelegate方法如果传入滚动视图则返回YES等于你要滚动到顶部的那个:

You can also implement the UIScrollViewDelegate method scrollViewShouldScrollToTop: and return YES if the passed in scroll view is equal to the one that you want to scroll to the top:

- (BOOL) scrollViewShouldScrollToTop:(UIScrollView*) scrollView {
    if (scrollView == self.myTableView) {
        return YES;
    } else {
        return NO;
    }
}

这篇关于无法在iOS7上使用scrollsToTop的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 07:47