您好我正试图像这样倾斜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
的高度,这是显而易见的,通过角度变换,视图需要被塑造为我的给定图片。但我无能为力,而且我尝试了很多方法。请帮我一些例子和清楚的解释。
提前致谢。