我想旋转两个图像,我将一个图像放在另一个图像后面,但是当我使用以下代码旋转它们时,后面的图像将在前面的图像之上,我分配了它们的 ZPOstion,但它们没有变化
这个链接是我在旋转之前查看的链接http://i39.tinypic.com/ivv2ah.png
并在旋转http://i43.tinypic.com/ic05xj.png
这是怎么发生的
[UIView animateWithDuration:0.2 animations:
^{
CALayer *myLayer=self.image2.layer;
CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.x"];
animation.fromValue = [NSNumber numberWithFloat:(1 * M_PI/Down)];
animation.toValue = [NSNumber numberWithFloat:(1 * M_PI/UP)];
animation.repeatCount =0;
animation.duration=0.2;
[animation setRemovedOnCompletion:NO];
animation.timingFunction = [CAMediaTimingFunction
functionWithName:kCAMediaTimingFunctionLinear];
[self.image2.layer addAnimation:animation forKey:@"transform.rotation.x"];
CATransform3D transform = CATransform3DIdentity;
transform.m34 = (1/500.0f);
transform = CATransform3DRotate(transform, (1 * M_PI/UP), 1, 0,0);
myLayer.transform=transform;
}
completion:^(BOOL finished)
{
self.image2.postion=@"UP";
}];
[UIView animateWithDuration:0.2 animations:
^{
CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.x"];
animation.fromValue = [NSNumber numberWithFloat:(1 * M_PI/Down)];
animation.toValue = [NSNumber numberWithFloat:(1 * M_PI/UP)];
animation.repeatCount =0;
animation.duration=0.2;
[animation setRemovedOnCompletion:NO];
animation.timingFunction = [CAMediaTimingFunction
functionWithName:kCAMediaTimingFunctionLinear];
[card.layer addAnimation:animation forKey:@"transform.rotation.x"];
CATransform3D transform = CATransform3DIdentity;
transform.m34 = (1/500.0f);
transform = CATransform3DRotate(transform, (1 * M_PI/UP), 1, 0,0);
card.layer.transform=transform;
}
completion:^(BOOL finished)
{
card.postion=@"UP";
}];
CArdImage 是自定义 UIImageView 这就是我改变的
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self)
{
self.layer.anchorPoint=CGPointMake(0.5, 1.0);
CATransform3D transform = CATransform3DIdentity;
transform.m34 = (1/500.0f);
transform = CATransform3DRotate(transform, (1 * M_PI/2.5), 0.5, 0,0);
self.layer.transform=transform;
self.postion=@"UP";
}
return self;
}