我正在编写一个基于UICollectionView和RxSwift/RxCocoa的小型图像查看器,以提供委托功能。我的目标是在从viewModel加载数据之后立即跳转到某个单元格。这是我到目前为止尝试过的。
ViewModel:
class ImageViewerViewModel {
let dataSource = BehaviorRelay<[UIImage]>(value: [])
let selectedImageIndex = BehaviorSubject<Int>(value: 0)
private let disposeBag
我有一个自定义的collectionView布局。此自定义布局增加了中心单元格的宽度。下面是执行此操作的自定义布局类。查看shiftedAttributes函数,了解它是如何完成的
class CustomCollectionViewLayout: UICollectionViewLayout {
private var cache = [IndexPath: UICollectionViewLayoutAttributes]()
private var contentWidth = CGFloat()
private var visibleLayoutAttribu
当我在模拟器上运行时,它工作正常。但是当我在物理设备上运行时,我面临一个错误-- index out of range。
代码:
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
let index = NSIndexPath(row: 0, section: 0) as IndexPath
resultController?.collectionView?.scrollToItem(at: index, at: .bottom, ani
我在视图控制器中使用UICollectionView,并传递了一个图像数组。我已经启用了集合视图的分页。但是当我滚动到下一个图像时,前一个单元格并没有完全消失。它仍然在边缘。所以,how I can make only specific image/cell visible while scrolling left/Right.
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
if coll
我们有一个使用自定义UICollectionView作为源的MvxCollectionViewSource。当选择一个项目时,我们想要滚动到第四项,做一个简短的动画,然后做一个动作。在源中,ItemSelected被覆盖,如下所示,其中为ScrollAnimationEnded设置了一个事件。
public override void ItemSelected(UICollectionView collectionView, NSIndexPath indexPath)
{
var item = GetItemAt(indexPath) as Slide