繁体   English   中英

UICollectionView didSelectItemAtIndexPath滚动

[英]UICollectionView didSelectItemAtIndexPath Scrolling

我正在使用CollectionView来显示图像。我正在使用启用分页的水平滚动,因此用户可以像在iOS上的应用程序屏幕上一样,从图像到图像从右向左滚动。 我如何能够调用didSelectItemAtIndexPath来检测收集视图停止在哪个单元格上,而无需用户点击该单元格?

虽然无关紧要:

- (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);

}

和图像

http://cl.ly/image/3x1R41073W2z

http://cl.ly/image/203Q2E3T2X44

非常感谢!

您可以在集合视图上调用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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM