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

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • 转自:https://www.jianshu.com/p/10b2323f502e 1、禁止手机睡眠 [UIApp...
    aggie1024阅读 2,853评论 0 6
  • 1、禁止手机睡眠 [UIApplication sharedApplication].idleTimerDisab...
    小小夕舞阅读 1,622评论 1 1
  • 一、简介 <<UITableView(或简单地说,表视图)的一个实例是用于显示和编辑分层列出的信息的一种手段 <<...
    无邪8阅读 10,946评论 3 3
  • 什么是智能对象?什么是连接对象?今天就分享两个基础知识,跟大家讲解一下这两个东西。 全教程完,学完记得交作业。如果...
    摇星学院阅读 368评论 0 0
  • 落叶飘离故土, 身影随风飘舞。 是谁在欢唱? 不,那是风在追逐。 / 月光撒下孤独, 思念在诉苦。 天涯家处处, ...
    草芥人阅读 319评论 0 0

友情链接更多精彩内容