水平和垂直两个方向滚动 [英] Scrolling horizontal and vertical both direction
问题描述
我需要水平和垂直滚动图像.
I have requirement to scroll the images horizontally and vertically.
我有部分将垂直分隔
和在每个部分本身会有很多图像将水平滚动
.
我使用 UICollectionView
和 Ray wenderlich 教程 但是如何在每个部分中进行水平滚动?
I made vertical scrolling using UICollectionView
with Ray wenderlich tutorial but how do I get horizontal scrolling in each section?
我应该为此使用任何其他对象,例如 UITableView
或 UIScrollview
吗?
Should I use any other object like UITableView
or UIScrollview
for this purpose?
有没有如何实现这一目标的教程?
Any tutorial available how to achieve this?
使用集合视图时是否必须实现Layout子类或UICollectionviewFlowlayout
?
编辑
到目前为止,我已经实现了这段代码,它垂直滚动,每个部分有 5 个部分,但无法滚动各个部分
Till now I have implemented this code which scrolls vertically and has 5 sections each but not able to scroll the individual sections
- (NSInteger)collectionView:(UICollectionView *)view numberOfItemsInSection:(NSInteger)section;
{
NSArray *arrayReturn = [self returnArray:section];
return arrayReturn.count;
}
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
return 5;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)cv cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
ImageCell *cell = [cv dequeueReusableCellWithReuseIdentifier:@"imagecell" forIndexPath:indexPath];
NSBlockOperation *operation = [NSBlockOperation blockOperationWithBlock:^{
NSArray *arrSection = [NSArray arrayWithArray:[self returnArray:indexPath.section]];
NSString *fileName = [arrSection objectAtIndex:indexPath.row];
UIImage *image = [UIImage imageNamed:fileName];
dispatch_async(dispatch_get_main_queue(), ^{
// cell.imgVw.image = ;
if([CollectionView.indexPathsForVisibleItems containsObject:indexPath]){
ImageCell *currentCell = (ImageCell *) [cv cellForItemAtIndexPath:indexPath];
currentCell.imgVw.image = image;
}
});
}];
[self.thumbnailQueue addOperation:operation];
return cell;
}
- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath
{
HeaderView *Header = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"PhotoHeaderView" forIndexPath:indexPath];
Header.lblHeaderTitle.text = @"Header title";
Header.backgroundColor = [UIColor yellowColor];
return Header;
}
推荐答案
这里有一个类似的教程:
Here is a similar tutorial:
基本上您需要执行以下操作:
Basically you need to do following:
- 采用 tableView 或 CollectionView
- 在每个单元格中,您需要添加一个启用水平滚动的滚动视图.
- 在创建单元格时添加项目以滚动每个单元格的视图,并为滚动视图提供适当的内容大小.
它会给你想要的结果.
这篇关于水平和垂直两个方向滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!