美文网首页
IOS 获取任意控件在屏幕中的坐标

IOS 获取任意控件在屏幕中的坐标

作者: 本客 | 来源:发表于2021-04-27 18:12 被阅读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];

相关文章

网友评论

      本文标题:IOS 获取任意控件在屏幕中的坐标

      本文链接:https://www.haomeiwen.com/subject/qrjprltx.html