I'm brand new to iPhone programming (and Cocoa) and I'm losing my mind on this. Why doesn't this approach work for me?
Here's my code in a custom view subclassed from UIView:
- (void) printViewDetails: (MyView *) v {
NSLog(@" Origin in local coordinates x:%f y:%f", v.frame.origin.x, v.frame.origin.y);
// what goes here???
CGPoint p = [v.superview convertPoint:v.frame.origin toView:nil];
NSLog(@" Origin in converted coordinates x:%f y:%f", p.x, p.y);
}
- (void) printViewLayout {
NSLog(@"Base view:");
[self printViewDetails:self];
NSLog(@"Subviews");
for (MyView *v in [self subviews]){
if ([v isKindOfClass:[MyView class]]) {
[self printViewDetails:v];
}
}
I created a view and add two subviews - all MyView instances. Here's the output:
2010-08-16 19:57:06.820 MyApp[33011:207] Base view:
2010-08-16 19:57:06.822 MyApp[33011:207] Origin in local coordinates x:30.000000 y:70.000000
2010-08-16 19:57:06.823 MyApp[33011:207] Origin in converted coordinates x:0.000000 y:0.000000
2010-08-16 19:57:06.824 MyApp[33011:207] Subviews
2010-08-16 19:57:06.825 MyApp[33011:207] Origin in local coordinates x:0.000000 y:0.000000
2010-08-16 19:57:06.825 MyApp[33011:207] Origin in converted coordinates x:0.000000 y:0.000000
2010-08-16 19:57:06.826 MyApp[33011:207] Origin in local coordinates x:69.000000 y:0.000000
2010-08-16 19:57:06.827 MyApp[33011:207] Origin in converted coordinates x:69.000000 y:0.000000
I've tried a dozen other approaches using convertPoint:toView, fromView, etc. and nothing works.
Any help is appreciated!
Thanks, David