francesco.venica
francesco.venica

Reputation: 1721

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?

Upvotes: 1

Views: 2045

Answers (1)

GWed
GWed

Reputation: 15653

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.

Upvotes: 2

Related Questions