缩放/动画UIView的一面是否更小? - CGAffineTransformMakeScale

时间:2014-05-19 23:44:57

标签: ios cocoa-touch core-animation uiviewanimation cgaffinetransform

我想为UIView设置动画,使其右侧变小,然后再返回。当点击此UIView中的UIButton时,将触发此动画。这是我想要的快速模型 - UIView将从状态1>状态2>州1:

Proposed Animation

看起来它被推到一边。

这是我对另一个动作的代码 - 这使得UIView再次变得越来越大,好像它被推到中心而不是侧面。

self.myView.transform = CGAffineTransformMakeScale(0.95,0.95);
self.myView.alpha = 1.f;

[UIView beginAnimations:@"button" context:nil];
[UIView setAnimationDuration:0.5];
self.myView.transform = CGAffineTransformMakeScale(1,1);
self.myView.alpha = 1.0f;
[UIView commitAnimations];

我如何应用同样的效果但仅适用于右侧?非常感谢任何帮助,谢谢!

1 个答案:

答案 0 :(得分:4)

根据这个question你需要以透视变换为例,我从我链接的那个问题中修改了一下

  CATransform3D perspectiveTransform = CATransform3DIdentity;
  perspectiveTransform.m34 = 1.0 / -500;
  perspectiveTransform = CATransform3DRotate(perspectiveTransform, 40.0f * M_PI / 180.0f, 0.0f, 1.0f, 0.0f);

  [UIView animateWithDuration:0.4 animations:^{
    self.myView.layer.transform = perspectiveTransform;

  }];

编辑2带回原版

 - (void)startAnimation:(id)sender
  {
     CATransform3D perspectiveTransform = CATransform3DIdentity;
     perspectiveTransform.m34 = 1.0 / -500;
     perspectiveTransform = CATransform3DRotate(perspectiveTransform, 40.0f * M_PI / 180.0f, 0.0f, 1.0f, 0.0f);
     [UIView animateWithDuration:1.4 animations:^{
     self.myView.layer.transform = perspectiveTransform;
     }completion:^(BOOL finished) {

      CATransform3D originalPerspectiveTransform = CATransform3DIdentity;
      [UIView animateWithDuration:0.9 animations:^{
         self.myView.layer.transform = originalPerspectiveTransform;
        }];
     }];

  }