Convert coordinates between parent/child UIView after CGAffineTransform - iphone

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];

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

Related

How to animate move of SubView from one view to the other?

how i can move a subview in a UIView to out of UIView frame, and see that value of outside in bottom! sorry please see my picture for understand, i dont want to use scrollview, and dont use duplicate views to do this.
thanks
You have to duplicate the subview. There's no other way, because you can't add the same subview twice.
If you try to add an existing subview to another view, it will be automatically removed from it's superview.
After the view is duplicated, you can animate both of them in the way you described.
UPDATE
Here create same two subview , after that set frame both like bellow...
- (void)viewDidLoad
{
yourSubview1.frame = CGRectMake(yourSubview1.frame.origin.x, 200, yourSubview1.frame.size.width, yourSubview1.frame.size.height);
yourSubview2.frame = CGRectMake(yourSubview2.frame.origin.x, 400, yourSubview2.frame.size.width, yourSubview2.frame.size.height);
}
and after when you want to move subview at that time just call bellow code ...
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.3];
yourSubview1.frame = CGRectMake(yourSubview1.frame.origin.x, yourSubview1.frame.origin.y - 100, yourSubview1.frame.size.width, yourSubview1.frame.size.height);
yourSubview2.frame = CGRectMake(yourSubview2.frame.origin.x, yourSubview2.frame.origin.y - 100, yourSubview2.frame.size.width, yourSubview2.frame.size.height);
//// set `y` where you want to display just like i minus the y with 100 so its move above with 100 point of y
[UIView commitAnimations];
This is just an example you can set this with your frame and timer ..
i hope this help you....

rotate UIView/UITableView around a point

I try to rotate a UITableView around a point, I use this IBAction that work only for half
CALayer *l = self.table.layer;
l.anchorPoint = CGPointMake(0,0);
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1];
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
CGAffineTransform rotate = CGAffineTransformMakeRotation(0.6);
table.transform = rotate;
[UIView commitAnimations];
when I click on the button firs of all the table move to another position than rotate around a corner...the problem is that the table move to another position at the beginning of animation..If I put
CALayer *l = self.table.layer;
l.anchorPoint = CGPointMake(0,0);
on viewdidload when I open application the tableview is to another position but the animation is correct, it's seems that l.anchorPoint move the table to another position...where is the error?
The problem is possibly with l.anchor.
The setAnchor method sets the centre point of frame in the layer. You have set the centre point in the top left corner (0,0). (1,1) would be the bottom right.
The layer positions itself by using the centre property. This represents the coordinates in the super layer. Because you have change the anchor point, your layer will be offset as the centre property is now being reference from the top left, but with the same sub layer coords.
If you set the anchor to (1,1) you would notice that the bottom right corner would now be where the top left corner was.
To solve your problem, set the anchor point and reposition your layer by setting centre property.
l.center = CGPoint (l.center.x - (l.frame.size.width/2), l.center.y - (l.frame.size.height/2);
The above code should do the trick.

Simulate push view animation inside UIView

I have a single UIView with some labels that display attributes from objects inside an array. I'm using gesture recognizers to change the current element in the array and hence the text in the labels. My question is how do I mimic a push animation without actually pushing a new view controller. Thanks for your help.
Thats simple way to use CGAffineTransformMakeTranslation to move any view from X axis to Y axis using UIViewAnimation. Before using this transition set your object frame to some x,y axis(0,0) and pass your x and y to move from.
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.4];
CGAffineTransform transform = CGAffineTransformMakeTranslation(x,y);
YOUR ViewOBJECT.transform=transform;
[UIView commitAnimations];
Have you tried to use the UIView class methods for animation? For example this could help:
+ (void)animateWithDuration:(NSTimeInterval)duration animations:(void (^)(void))animations
In the animations block you could move one view out and another in.

Opening a curtain: Animation with Core Animation

I would like to animate a curtain, which gets opened. I have two images: one for the left and one for the right side of the curtain (depicted in red). I would like to smoothly slide them away with Core Animation. For what animation type should I look for? How do I achieve a realistic sliding style?
Regards,
Stefan
alt text http://img.skitch.com/20100627-8ytxrbe64ccbruj49c2pbs7kt2.png
I'm not sure why people are suggesting using a translation. If all you need to do is slide the images, simply call -setCenter on each image view inside an animation block. Like this:
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1.0];
[leftCurtainImageView setCenter:pointOffScreenLeft];
[rightCurtainImageView setCenter:pointOffScreenRight];
[UIView commitAnimations];
Where pointOffScreenLeft, and pointOffScreenRight are calculated something like:
CGPoint pointOffScreenLeft = CGPointMake(
-[leftCurtainImageView bounds].size.width,
[leftCurtainImageView frame].origin.y);
CGPoint pointOffScreenRight = CGPointMake(
[rightCurtainImageView frame].origin.x +
[rightCurtainImageView bounds].size.width,
[leftCurtainImageView frame].origin.y);
These calculations assume that the curtains are positioned at the far left and far right edges respectively of their containing view.
The easiest solution would be to have to imageview or CGLayers and then use CGAffineTransformTranslate in an animation block to slide them off screen.
Man
After a long search. The only way I could find is this.
https://github.com/Ciechan/BCMeshTransformView

UIView Animation iPhone (obtaining information on the frame dynamically)

I have a UIView called goalBar which is being animated by increasing the size of the frame according to a float value called destination:
CGRect goalBarRect = CGRectMake(0, 0, destination, 29);
[UIView beginAnimations:#"goal" context:nil];
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
[UIView setAnimationDuration:2.0f];
goalBar.frame = goalBarRect;
[UIView commitAnimations];
The animation works perfectly and the rectangular view increases its width over the course of the animation (from 0 to the value for destination).
However, I wish to be able to extract the values for the frame of the UIView being animated (i.e. goalBar) as the animation takes place. By that I mean that I wish to place the value of the width for the animated frame in a separate UILabel so that the user sees a counter that provides the width of the UIView as it's being animated.
Any help on how to do the above would be gratefully received.
How about observing the frame property of the view. So that you get callbacks when it changes.
See Key-Value Observing.
I've looked into this and it seems that it is not possible to get updates on the state of the components being animated during the UIView animation process.