IOS 获取任意控件在屏幕中的坐标
2021-04-27 本文已影响0人
本客
//获取view在屏幕中的位置
UIWindow * Window =[[[UIApplication sharedApplication] delegate] window];
CGRect rect =[view convertRect:view.bounds toView:Window];
//获取网格cell在屏幕中的位置
//先获取需要获取位置的cell
UICollectionViewCell * cell = (UICollectionViewCell *)[collectionView cellForItemAtIndexPath:indexPath];
//cell在当前collection的位置
CGRect cellRect = [_collectionView convertRect:cell.frame toView:_collectionView];
//cell在当前屏幕的位置
CGRect rect2 = [_collectionView convertRect:cellRect toView:self.view];