1

我想旋转两个图像,我将一个图像放在另一个图像后面,但是当我使用以下代码旋转它们时,后面的图像将在前面的图像之上,我分配了它们的 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;
 }
4

1 回答 1

0

一个可能的原因是动画彼此不同步。尝试将两个动画块放在一起:

[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;

     // second animation code
     CABasicAnimation *animation2 = [CABasicAnimation animationWithKeyPath:@"transform.rotation.x"];
     animation2.fromValue = [NSNumber numberWithFloat:(1 * M_PI/Down)]; 
     animation2.toValue = [NSNumber numberWithFloat:(1 * M_PI/UP)]; 
     animation2.repeatCount =0;
     animation2.duration=0.2;
     [animation2 setRemovedOnCompletion:NO];
     animation2.timingFunction = [CAMediaTimingFunction
                                 functionWithName:kCAMediaTimingFunctionLinear]; 
     [card.layer addAnimation:animation2 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)
 {
     self.image2.postion=@"UP";
     card.postion=@"UP";
 }];
于 2012-04-08T14:26:22.197 回答