简体   繁体   English

X方向旋转两个UIImageView

[英]Rotating Two UIImageView in X Direction

i wanna rotate two images i put one images behind the other but when i rotate them with the following code the back image will be above the front image and i assign their ZPOstion but their is no change我想旋转两张图片,我将一张图片放在另一张图片后面,但是当我使用以下代码旋转它们时,背面图像将位于正面图像上方,我分配了它们的 ZPOstion 但它们没有变化

this link for my view before rotate http://i39.tinypic.com/ivv2ah.png此链接供我在旋转之前查看http://i39.tinypic.com/ivv2ah.png

and after rotate http://i43.tinypic.com/ic05xj.png旋转后http://i43.tinypic.com/ic05xj.png

how this happen这是怎么发生的

 [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 is Custom UIImageView and this is what i Change CArdImage 是 Custom 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;
 }

A probable reason for this is that the animations are not synchronized with each other.一个可能的原因是动画彼此不同步。 Try by putting both the animation blocks together:尝试将两个 animation 块放在一起:

[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";
 }];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM