ios - 动画类卡片app iphone

标签 ios iphone core-animation flip cabasicanimation

我正在尝试实现与卡片应用程序 ( 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];
}

谢谢。

最佳答案

要创建必要的动画,您可以使用 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];
      }];
   }];
}

关于ios - 动画类卡片app iphone,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20350606/

相关文章:

iphone - 你如何设计 iOS 组件的样式?

objective-c - animateWithDuration 立即完成

ios:如何为所有iphone屏幕设置动态高度

iphone - 如何使按钮的文字向左对齐?

ios - 在 Swift 3 中从 AudioBufferList 中提取数据

iphone - 注册应用程序以从 Safari 的 "share"或 "open in..."对话框打开不起作用。 (虽然适用于其他应用程序)

iphone - 防止重复的 NSArray(一个已排序,一个未排序)

iphone - 解析 RSS 提要困难

cocoa - 将 CAAnimation 实例添加到图层后,可以通过修改它来重用它吗?

ios - iOS 中的断断续续的动画