[英]UICollectionView didSelectItemAtIndexPath Scrolling
I am using a CollectionView to display an image in. I am using horizontal scrolling with pagination enabled so the user is able to scroll from image to image right to left as they would on the apps screen on iOS. 我正在使用CollectionView来显示图像。我正在使用启用分页的水平滚动,因此用户可以像在iOS上的应用程序屏幕上一样,从图像到图像从右向左滚动。 How might I be able to call didSelectItemAtIndexPath to detect which cell the collection view has stopped on without the user having to tap on the cell? 我如何能够调用didSelectItemAtIndexPath来检测收集视图停止在哪个单元格上,而无需用户点击该单元格?
Though it is not relevant: 虽然无关紧要:
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
titleLabel.alpha = 1.0;
mainTextLabel.alpha = 1.0;
availableLabel.alpha = 1.0;
sizeLabel.alpha = 0.0;
sizeImage.alpha = 0.0;
moreInfoOnSize.alpha = 0.0;
UICollectionViewCell *datasetCell =[collectionView cellForItemAtIndexPath:indexPath];
datasetCell.backgroundColor = [UIColor lightGrayColor]; // highlight selection
PFObject *selectedObject = [labelFileArray objectAtIndex:indexPath.row];
titleLabel.text = selectedObject[@"labelText"];
PFObject *selectedObject2 = [mainTextArray objectAtIndex:indexPath.row];
mainTextLabel.text = selectedObject[@"mainTextLabel"];
PFObject *selectedObject3 = [availableLabelArray objectAtIndex:indexPath.row];
availableLabel.text = selectedObject[@"availableLabel"];
if ([availableLabel.text isEqual:@"Available"]) {
availableLabel.backgroundColor = [UIColor greenColor];
} else if ([availableLabel.text isEqual:@"Sorry We Are Out!"])
{
availableLabel.backgroundColor = [UIColor redColor];
}
NSLog(@"%@", indexPath);
}
And Image 和图像
http://cl.ly/image/3x1R41073W2z http://cl.ly/image/3x1R41073W2z
http://cl.ly/image/203Q2E3T2X44 http://cl.ly/image/203Q2E3T2X44
Thank you so much! 非常感谢!
You can call visibleCells
on your collection view to get the cells currently visible on the screen like this: 您可以在集合视图上调用visibleCells
,以使当前在屏幕上可见的单元格如下所示:
// All visible cells (1 or more depending on your layout and cell sizes)
NSArray *visibleCells = [myCollectionView visibleCells];
// Get the first cell from the array
UICollectionViewCell *firstCell = visibleCells.firstObject;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.