Possible Duplicate:
How do I apply a perspective transform to a UIView?
Hi I am trying to tilt an UIView like this :
I want to do it using CATransform3DRotate and other Core functions. Is it possible?
What I have done so far: I have a method in which I create a orange colored view named LowerTable.
-(void)createShelf
{
CGRect parentFrame=parent.frame;
float width=200;
float height=200;
lowerTable=[[UIView alloc] init];
lowerTable.backgroundColor=[UIColor orangeColor];
lowerTable.frame=CGRectMake(60, parentFrame.size.height/2, width, height);
[self setAnchorPoint:CGPointMake(0.5, 0) forLayer:lowerTable.layer];
[parent addSubview:lowerTable];
}
The setAnchorPoint method is as below:
//sets the anchor point of the layer in proper place.
-(void)setAnchorPoint:(CGPoint)anchorPoint forLayer:(CALayer *)layer
{
CGPoint newPoint = CGPointMake(layer.bounds.size.width * anchorPoint.x, layer.bounds.size.height * anchorPoint.y);
CGPoint oldPoint = CGPointMake(layer.bounds.size.width * layer.anchorPoint.x, layer.bounds.size.height * layer.anchorPoint.y);
newPoint = CGPointApplyAffineTransform(newPoint,CATransform3DGetAffineTransform(layer.transform));
oldPoint = CGPointApplyAffineTransform(oldPoint,CATransform3DGetAffineTransform(layer.transform));
CGPoint position = layer.position;
position.x -= oldPoint.x;
position.x += newPoint.x;
position.y -= oldPoint.y;
position.y += newPoint.y;
layer.position = position;
layer.anchorPoint = anchorPoint;
}
Once anchor point and the view is set I am calling the following method on tapping a button ,to apply the transform :
-(void)animateLayer:(CALayer *)layer
{
[UIView animateWithDuration:2 delay:0.0 options:UIViewAnimationOptionAllowAnimatedContent animations:^{
CATransform3D _3Dt = layer.transform;
_3Dt = CATransform3DRotate(_3Dt, 30*M_PI/180, 1, 0, 0.0);
layer.zPosition=2000;
layer.transform=_3Dt;
} completion:^(BOOL finished) {
}];
}
What it is doing is that simply decreasing the height of the UIView, which is obvious, with angle transform the view needs to be shaped as my given picture. But I'm unable and I have tried many ways. Please help me with some examples and clear explanation.
Thanks in advance.