繁体   English   中英

- (CGRect)convertRect:(CGRect)rect toView:(nullable UIView *)view

[英]- (CGRect)convertRect:(CGRect)rect toView:(nullable UIView *)view

UIView *sourceView = self.sourceImagesContainerView.subviews[self.currentImageIndex];
UIView *parentView = [self getParsentView:sourceView];
CGRect rect = [sourceView.superview convertRect:sourceView.frame toView:parentView];
NSLog(@"%@",NSStringFromCGRect(rect));

在tableView中用于获取imageView到另一个view的位置,但是当我滑动tableView时,rect是错误的。

我不知道如何处理这个。

除非您准备减去 contentOffset,否则您不能使用 tableView 作为此转换的父级。

UIView *sourceView = self.sourceImagesContainerView.subviews[self.currentImageIndex];
UITableView *parentView = self.tableView;
CGRect rect = [sourceView.superview convertRect:sourceView.frame toView:parentView];
rect = CGRectOffset(rect, 0-parentView.contentOffset.x, 0-parentView.contentOffset.y);
NSLog(@"%@",NSStringFromCGRect(rect));

最好使用非滚动父级:

UIView *sourceView = self.sourceImagesContainerView.subviews[self.currentImageIndex];
UIView *parentView = self.navigationController.view;
CGRect rect = [sourceView.superview convertRect:sourceView.frame toView:parentView];
NSLog(@"%@",NSStringFromCGRect(rect));

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM