我有一个应用程序,其中有很多UIView's
嵌套在一起。
我想找到一些UIView's
关于Controller的框架。
我有一个例子:
我可以找到White UIView
WRT的框架,Controller
但是如何找到RedView
Controller的WRT框架。
查找框架的代码White View
:
- (void)viewDidAppear:(BOOL)animated
{
NSLog(@"--OuterFrame---%@",NSStringFromCGRect(self.grayView.frame));
NSLog(@"--InnerFrame---%@",NSStringFromCGRect(self.whiteView.frame));
NSLog(@"---Frame With resepect to self.view --%@",NSStringFromCGRect([self.grayView convertRect:self.whiteView.frame toView:self.view]));
}
如果他们是红色视图中的另一种视图怎么办。
您有正确的总体思路。但是,如果您使用内部视图的bounds
,并使用self.view
进行转换,则会更容易:
// assumes innerView is a view somewhere underneath self.view
CGRect innerViewRectRelativeToController =
[self.view convertRect:innerView.bounds fromView:innerView];
这样,您只需要指定要从中转换的视图和要转换为的视图即可。您无需考虑两者之间的视图。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句