xcode 将 UITable 中 UITableViewCell 子视图中对象的 CGRect 转换为相对于 self.view 的 CGRect
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3010594/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Converting a CGRect of a object in a subview in UITableViewCell in UITable to CGRect with respect to self.view
提问by David Gao
I want to convert a CGRect
"aRect" of a object in a subview in UITableViewCell
in UITableView
to CGRect
with respect to self.view
.
我想转换CGRect
一个对象的“aRect”在子视图中UITableViewCell
在UITableView
以CGRect
相对于self.view
。
The problem is that aRect is with respect to the subview in the table cell.
But i want to make it so that it is with respect to self.view
.
问题是 aRect 与表格单元格中的子视图有关。但我想让它与self.view
.
What i tried is this
我试过的是这个
rect = [self.view convertRect:aRect.frame toView:cellView];
but it doesn't work.
但它不起作用。
So how to convert it?
那么如何转换呢?
回答by Evadne Wu
Since convertRect:toView:
actually deals with a CGRect
in the receiver's coordinate system,maybe [cellView convertRect:theFrame toView:self.view]
(i.e. swapping the two views in your call) will work as you intended.
因为convertRect:toView:
实际上涉及一个CGRect
接收器的坐标系中,也许[cellView convertRect:theFrame toView:self.view]
(即交换在呼叫的两个视图)将按照您预期。