collectionViewCell,位置怎么获取啊
1个回答
展开全部
-(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);
}
{
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);
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询