UICollectionView:像Safari选项卡或App Store搜索一样分页 [英] UICollectionView: paging like Safari tabs or App Store search

查看:148
本文介绍了UICollectionView:像Safari选项卡或App Store搜索一样分页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的应用中实现卡片,例如Safari标签或App Store搜索。

I want to implement "cards" in my app like Safari tabs or App Store search.

我会在屏幕中心向用户显示一张卡片左侧和右侧的上一张和下一张牌。 (例如,请参阅App Store搜索或Safari选项卡)

I will show user one card in a center of screen and part of previous and next cards at left and right sides. (See App Store search or Safari tabs for example)

我决定使用 UICollectionView ,我需要更改页面大小(没找到怎么样)或者实现自己的布局子类(不知道怎么做)?

I decided to use UICollectionView, and I need to change page size (didn't find how) or implement own layout subclass (don't know how)?

请帮忙吗?

推荐答案

以下是我发现获得此效果的最简单方法。它涉及您的收藏视图和额外的秘密滚动视图。

Below is the simplest way that I've found to get this effect. It involves your collection view and an extra secret scroll view.

设置您的收藏视图


  • 设置集合视图及其所有数据源方法。

  • 构建集合视图;它应该跨越你想要显示的整个宽度。

  • 设置集合视图的 contentInset

_collectionView.contentInset = UIEdgeInsetsMake(0, (self.view.frame.size.width-pageSize)/2, 0, (self.view.frame.size.width-pageSize)/2);


这有助于正确抵消细胞。

This helps offset the cells properly.

设置秘密卷轴视图


  • 创建滚动视图,把它放在任何你喜欢的地方。如果您愿意,可以将其设置为隐藏

  • 将scrollview的边界大小设置为所需的页面大小。

  • 将自己设置为scrollview的委托。

  • contentSize 设置为预期内容收藏视图的大小。

  • Create a scrollview, place it wherever you like. You can set it to hidden if you like.
  • Set the size of the scrollview's bounds to the desired size of your page.
  • Set yourself as the delegate of the scrollview.
  • Set its contentSize to the expected content size of your collection view.

移动手势识别器


  • 将秘密scrollview的手势识别器添加到集合视图,并禁用集合视图的手势识别器:

  • Add the secret scrollview's gesture recognizer to the collection view, and disable the collection view's gesture recognizer:

[_collectionView addGestureRecognizer:_secretScrollView.panGestureRecognizer];
_collectionView.panGestureRecognizer.enabled = NO;


代表

- (void) scrollViewDidScroll:(UIScrollView *)scrollView {
    CGPoint contentOffset = scrollView.contentOffset;
    contentOffset.x = contentOffset.x - _collectionView.contentInset.left;
    _collectionView.contentOffset = contentOffset;
}

当滚动视图移动时,获取其偏移量并将其设置为偏移量集合视图。

As the scrollview moves, get its offset and set it to the offset of the collection view.

我在这里写了博客,所以请查看此链接以获取更新: http://khanlou.com/2013/04/paging-a-overflowing-collection-view/

I blogged about this here, so check this link for updates: http://khanlou.com/2013/04/paging-a-overflowing-collection-view/

这篇关于UICollectionView:像Safari选项卡或App Store搜索一样分页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆