可能重复:
如何将透视变换应用于 UIView?
嗨,我正在尝试UIView
像这样倾斜:
我想使用CATransform3DRotate
其他核心功能来做到这一点。可能吗?
到目前为止我所做的:我有一个方法可以创建一个名为 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];
}
setAnchorPoint 方法如下:
//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;
}
设置锚点和视图后,我将在点击按钮时调用以下方法以应用变换:
-(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) {
}];
}
它所做的是简单地降低 的高度UIView
,这很明显,通过角度变换,视图需要被塑造成我给定的图片。但是我做不到,我尝试了很多方法。请帮助我提供一些示例和清晰的解释。
提前致谢。