views:

1116

answers:

2

Hi

Before I go into doing everything by hand I would like to ask if there is some help to get from the framework.

I have a UIView that holds another UIView with a map. The parent UIView holds some legends for the map. Initially I define some coordinates in the map view. e.g. (100, 40), and place a piece of graphics there in the parent view (like a tack in google maps etc.). The parent view and the child view are both 300x200 and have the same origin. This means that (100, 40) is the same point in both views.

Now I zoom and move the child UIView(the map) using CGAffineTransform and the coordinate (100, 40) is now situated somewhere else. The parent view is effectively a mask here.

Can I use the CGAffineTransform Matrix or another part of the framework to calculate and inform the parent view where to place the tack now that the point has moved?

i.e. (100, 400) in the child view compared to (100, 40) in the parent view, what does it compare to after the transformation?

Thank you for suggestions or help given.

The animation of the child UIView

    [UIView beginAnimations:nil context:nil]; 
    [UIView setAnimationDuration:1.0]; 
    CGAffineTransform transform = CGAffineTransformMakeScale(1.8f, 1.8f);
    worldMap.transform = transform;
    worldMap.bounds.origin = newPos;
    [UIView commitAnimations];
+4  A: 

UIView's -convertPoint:toView: and -convertPoint:fromView: should work for you.

Costique
Costique is correct, there's no need to do the matrix math yourself. You have the whole view hierarchy system to help you.
NSResponder
deleted and moved to an answer instead
RickiG
A: 

Hi Costique, and thanks.

Sorry code in the comments is no good, so I'll post it like this.

Im a bit vague on how. The documentation doesn't help me enough here. I tried placing this in the child view and call it each time the parent view is tapped. self.increment += 0.1f;

self.newPosition = [self convertPoint:self.originPoint.frame.origin toView:self.superview];

  [UIView beginAnimations:nil context:nil]; 
  [UIView setAnimationDuration:1.0]; 
  CGAffineTransform transform = CGAffineTransformMakeScale(self.increment, self.increment);
  worldMap.transform = transform;
  [UIView commitAnimations];

It never changes the value, I read the newPosition from the super view, but no matter how much I scale it, it stays the same.

RickiG
Turns out I must be the views coordinates(center or origin) and not just a point inside the child view.Thanks again.
RickiG