简体   繁体   English

UICollectionView didSelectItemAtIndexPath滚动

[英]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.

相关问题 UICollectionView不调用didSelectItemAtIndexPath - UICollectionView not calling didSelectItemAtIndexPath didSelectItemAtIndexPath方法不在UICollectionView中工作 - didSelectItemAtIndexPath method not working in a UICollectionView UICollectionView didSelectitematIndexPath委托吗? - UICollectionView didselectitematindexpath delegate? 未调用 UICollectionView 的 didSelectItemAtIndexPath - didSelectItemAtIndexPath of UICollectionView is not called Swift UICollectionView:didSelectItemAtIndexPath没有响应 - Swift UICollectionView : didSelectItemAtIndexPath not responding 为什么UICollectionView在滚动其单元格的scrollView后不再调用didSelectItemAtIndexPath? - why UICollectionView not calling didSelectItemAtIndexPath any more after scrolling the scrollView of it's cells? didSelectItemAtIndexPath修改UICollectionView中的多个单元格 - didSelectItemAtIndexPath modifying multiple cells in UICollectionView didSelectItemAtIndexPath并不总是在UICollectionView的第一个元素上调用 - didSelectItemAtIndexPath not always called on first element in UICollectionView UICollectionView的didSelectItemAtIndexPath方法仅被调用一次 - UICollectionView's didSelectItemAtIndexPath method is called only once 在 UITextView 上点击时未调用 UICollectionView didSelectItemAtIndexPath - UICollectionView didSelectItemAtIndexPath not called when tapped on UITextView
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM