如何使用storyboard将集合视图节项目滚动到水平 [英] how to scroll collection view section item to horizontal using storyboard

查看:118
本文介绍了如何使用storyboard将集合视图节项目滚动到水平的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在水平卷动一个集合视图节项目。
收藏视图中可能有多个部分。

I am trying to scroll in horizontal of a collection view section item. There may be multiple section in collection view.

推荐答案

您尝试过这种方法吗?

-(void)scrollToItemAtIndexPath:(NSIndexPath *)indexPath atScrollPosition:(UICollectionViewScrollPosition)scrollPosition animated:(BOOL)animated

或者,除了滚动到项目,还可以scrollRectToVisible:sectionRect。

Or, besides scrolling to item, you can scrollRectToVisible:sectionRect. This example scrolls to a first item in a given section also considering the header view.

- (void)scrollToSection:(NSUInteger)section
{
    if ([self.collectionView numberOfItemsInSection:section] > 0) {

        UICollectionViewLayoutAttributes *attributes = [self.collectionView layoutAttributesForItemAtIndexPath:[NSIndexPath indexPathForItem:0 inSection:section]];

        CGRect sectionRect = CGRectMake(0, attributes.frame.origin.y - 65, self.collectionView.frame.size.width, self.collectionView.frame.size.height); // 65 is height of the header view

        [self.collectionView scrollRectToVisible:sectionRect animated:YES];

    } else {

        NSLog(@"no cell to scroll to");
    }
}

这篇关于如何使用storyboard将集合视图节项目滚动到水平的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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