在X方向旋转两个UIImageView [英] Rotating Two UIImageView in X Direction

查看:151
本文介绍了在X方向旋转两个UIImageView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想旋转两张图片我把一张图片放在另一张图片后但是当我用下面的代码旋转它们时,后面的图像将在前面的图像上方
并且我分配了他们的ZPOstion但是它们没有变化

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

旋转之前我的视图链接 http:// i39。 tinypic.com/ivv2ah.png

this link for my view before rotate 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,这就是我的变化

CArdImage is Custom UIImageView and this is what i Change

- (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:

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

这篇关于在X方向旋转两个UIImageView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆