获取collectionViewcCell及tableViewCell在当前屏幕的位置大小

●  获取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]];

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值