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

来源:互联网 发布:千百撸最新域名获取器 编辑:程序博客网 时间:2024/06/05 10:40
●  获取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
原创粉丝点击