美文网首页
获取collectionViewcCell及tableViewC

获取collectionViewcCell及tableViewC

作者: 小刘_假装是个程序员 | 来源:发表于2019-01-23 15:11 被阅读0次

    ● 获取collectionViewcCell在当前屏幕的位置大小
    -(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
    {

    UICollectionViewCell * cell = (UICollectionViewCell *)[collectionView cellForItemAtIndexPath:indexPath];
    //临时改变个颜色,看好,只是临时改变的。如果要永久改变,可以先改数据源,然后在cellForItemAtIndexPath中控制。(和UITableView差不多吧!O(∩_∩)O~)
    // cell.backgroundColor = [UIColor greenColor];
    // NSLog(@"item======%ld",(long)indexPath.item);
    // NSLog(@"row=======%ld",(long)indexPath.row);
    // NSLog(@"section===%ld",(long)indexPath.section);
    // NSLog(@"123456789--%f",cell.bounds.size.height);

    /*
    获取当前点击的cell位置大小,以此设定view2初始大小和位置
    */
    //cell在当前collection的位置
    CGRect cellRect = [_collectionView convertRect:cell.frame toView:_collectionView];
    NSLog(@"987654321- %f - %f # %f - %f",cellRect.origin.x,cellRect.origin.y,cellRect.size.width,cellRect.size.height);
    //cell在当前屏幕的位置
    CGRect rect2 = [_collectionView convertRect:cellRect toView:self.view];
    NSLog(@"987654321- %f - %f # %f - %f",rect2.origin.x,rect2.origin.y,rect2.size.width,rect2.size.height);
    }

    ● 获取tableViewcCell在当前屏幕的位置大小
    CGRect rectInTableView = [tableView rectForRowAtIndexPath:indexPath];
    CGRect rect = [tableView convertRect:rectInTableView toView:[tableView superview]];

    相关文章

      网友评论

          本文标题:获取collectionViewcCell及tableViewC

          本文链接:https://www.haomeiwen.com/subject/smojjqtx.html