xcode 如何始终在 UICollectionView 上显示滚动条

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16551122/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 03:22:57  来源:igfitidea点击:

How To Show Scrollbar Always On UICollectionView

iosxcodescrollbaruicollectionview

提问by motionpotion

I have a UICollectionView added to a UIView in an app I am working on. Displayed in the UICollectionView I have a set of images pulled from Core Data. The vertical scrolling works fine but the scrollbar does not display until the user touches the UICollectionView.

我有一个 UICollectionView 添加到我正在开发的应用程序中的 UIView 中。在 UICollectionView 中显示我有一组从 Core Data 中提取的图像。垂直滚动工作正常,但直到用户触摸 UICollectionView 才会显示滚动条。

How can I make sure the scrollbar at the right is always visible so that an indication is given to the user that it is scrollable?

如何确保右侧的滚动条始终可见,以便向用户指示它是可滚动的?

回答by DrummerB

You can't make them always visible. Instead, you can flash them once, when the user is first presented with the collection view to notify them, that this view can be scrolled.

您无法让它们始终可见。相反,您可以将它们闪现一次,当用户第一次看到集合视图以通知他们该视图可以滚动时。

Since UICollectionViewis a subclass of UIScrollViewyou can do this:

因为UICollectionViewUIScrollView你的子类,你可以这样做:

[myCollectionView flashScrollIndicators];

Check out the Settings app for instance. When you go to a settings list that is longer then the screen, the scroll indicator is flashed once.

例如,查看设置应用程序。当您进入比屏幕更长的设置列表时,滚动指示器会闪烁一次。

回答by Azin Mehrnoosh

FYI for Swift:

Swift 的仅供参考:

myCollectionView.flashScrollIndicators()