【问题标题】:Animation like cards app iphone动画像卡片应用程序 iphone
【发布时间】:2013-12-19 11:28:18
【问题描述】:

我正在尝试实现与卡片应用程序 (http://www.youtube.com/watch?v=aWjX_qufmc0) 中相同的效果,用于打开里面的内容(水平贺卡打开类型动画:https://store.marathonpress.com/image/cache/data/store_381/Previews/Press-Printed-Card-Folded-5x7-H-C-500x500.jpg)。我用CABasicAnimation试过了,但无法访问,谁能帮我实现同样的动画效果。

我正在尝试这样:

- (void)loadInsideMessageView {

    [UIView transitionWithView:backgroundView
                      duration:1.0
                       options:UIViewAnimationOptionTransitionFlipFromBottom //any animation
                    animations:^ {
                        insideView.frame = CGRectMake(0, 40, 568, 280);
                        [backgroundView addSubview:insideView];
                    }
                    completion:nil];
}

谢谢。

【问题讨论】:

    标签: ios iphone core-animation flip cabasicanimation


    【解决方案1】:

    要创建必要的动画,您可以使用Core Animation Function

    创建新的Single View Application项目并将下面的代码插入ViewController.m,看看它是如何工作的。

    - (void)viewDidLoad {
      [super viewDidLoad];
      [[self view] setBackgroundColor:[UIColor grayColor]];
    
      //create frame for 2 test views
      CGRect frame = CGRectMake(50.0, 100.0 , 200.0 ,100.0);
    
      //lower view
      UIView *insideViev = [[UIView alloc] initWithFrame: frame];
      [insideViev setBackgroundColor:[UIColor redColor]];
    
      //upper view
      UIView *pageView = [[UIView alloc] initWithFrame:frame];
      [pageView setBackgroundColor:[UIColor greenColor]];
    
      [[self view] addSubview:insideViev];
      [[self view] addSubview:pageView];
    
      //get layer of upper view and set needed property
      CALayer *viewLayer = [pageView layer];
      [viewLayer setAnchorPoint:(CGPoint){0.5 , 0.0}];
      [viewLayer setFrame:frame];
    
      //create perspective
      CATransform3D mt = CATransform3DIdentity;
      mt.m34 = 1.0/-500.;
    
      //create rotation
      CATransform3D open = CATransform3DMakeRotation(3 * M_PI_4, 1, 0, 0);
    
      //create result transform
      CATransform3D openTransform = CATransform3DConcat(open, mt);
    
      [UIView animateWithDuration:3.0 animations:^
       {
     //close animation
     [viewLayer setTransform:openTransform];
       } completion:^(BOOL finished)
       {
         [UIView animateWithDuration:3.0 animations:^
          {
            //close animation
            [viewLayer setTransform:CATransform3DIdentity];
          }];
       }];
    }
    

    【讨论】:

    • 谢谢@ruslan,太好了。但我有两个问题,(1)。我希望动画应该出现在顶部的灰色导航栏上,因为它现在出现在它的顶部。 (2)。转换后的视图上也出现了它的图像,它可以是简单的白色吗?它不应该显示图像的阴影,我可以将其更改为 alpha 或其他相关方法吗?请看截图!enter image description here
    • 我已经设法通过将子视图添加到顶视图 [backgroundView insertSubview:selectedTemplateImgView belowSubview:navBar] 来完成第一个问题;但仍然需要第二个解决方案的帮助。
    • 我能想到的第二个问题 - 您可以在图层下方添加图层(默认的 UIView 包含 1 层,但它可以包含超过 1 层),并为两个图层设置动画。
    • 在本教程中Create a 3D Page Folding Animation: Page Sketch & Spine Fold Effect 很好地说明了这一点:有一个平行的层层次结构对应于屏幕上的视图层次结构。这意味着如果(比如说)标签是按钮的子视图,那么标签的层就是按钮层的子层。严格来说,这种并行性仅在我们不将自己的子层添加到混合中时才成立。
    • 也可能有助于理解层的解剖结构:Building a Layer Hierarchy from Apple
    猜你喜欢
    • 2021-08-10
    • 1970-01-01
    • 2012-04-16
    • 1970-01-01
    • 2014-05-13
    • 2011-12-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多