【问题标题】:How to do animation like app launch when you tap on the app icon on iOS homescreen?当您点击iOS主屏幕上的应用程序图标时,如何制作类似应用程序启动的动画?
【发布时间】:2014-10-16 15:02:40
【问题描述】:

我想做一些类似于在 ios 主屏幕上启动应用程序的动画。就像整个集合视图放大一样,启动的应用程序覆盖了整个屏幕。

我正在使用 iOS 7 的新 api 进行视图控制器转换。 我正在使用父集合视图控制器快照来制作适当的动画。 但是我仍然对当时正在发生的动画感到不够了解?

【问题讨论】:

    标签: ios objective-c ios7 core-animation uicollectionview


    【解决方案1】:

    要获得所需的性能和外观,您可能必须对视图层执行转换。

    我在GitHub上放了一个小demo,相关代码如下。

    - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
    {
        MyCellView *cell = (MyCellView *)[self collectionView:collectionView cellForItemAtIndexPath:indexPath];
    
        self.detailViewController = [[DetailViewController alloc] initWithNibName:nil bundle:nil];
        self.detailViewController.labelString = [NSString stringWithFormat:@"%i", indexPath.row];
        [self.view.superview addSubview:self.detailViewController.view];
    
        // tap position relative to collection view
        float screenX = self.collectionView.frame.origin.x + cell.center.x;
        float screenY = self.collectionView.frame.origin.y + cell.center.y - self.collectionView.contentOffset.y;
    
        // tap position relative to view frame
        float translateX = (self.view.frame.size.width / -2.0) + screenX;
        float translateY = (self.view.frame.size.height / -2.0) + screenY;
    
        CATransform3D transform_detail = CATransform3DScale(CATransform3DMakeTranslation(translateX, translateY, 0.0), 0.0, 0.0, 0.0);
        CATransform3D transform_main = CATransform3DScale(CATransform3DMakeTranslation(-translateX * 5.0, -translateY * 5.0, 0.0), 5.0, 5.0, 5.0);
    
        self.detailViewController.view.layer.transform = transform_detail;
    
        [UIView animateWithDuration:0.5 animations:^{
            self.detailViewController.view.layer.transform = CATransform3DIdentity;
            self.view.layer.transform = transform_main;
        } completion:^(BOOL finished) {
            self.view.layer.transform = CATransform3DIdentity;
        }];
    }
    

    【讨论】:

    • 谢谢。您可以在 github 上的示例项目中添加反向动画,例如“当您点击主页按钮并且应用程序进入后台时”?或者,也许您只能在这里给出一个小提示。
    • 您只需反转动画...即您将从 CATransform3DIdentity 转换为“transform_detail”的 detailView。主视图将从“transform_main”转到 CATransform3DIdentity。
    【解决方案2】:

    您需要使用自定义转场。

    This 教程应该对你有所帮助,下面是代码摘录。

    - (void)perform {
        UIViewController *sourceViewController = self.sourceViewController;
        UIViewController *destinationViewController = self.destinationViewController;
    
        // Add the destination view as a subview, temporarily
        [sourceViewController.view addSubview:destinationViewController.view];
    
        // Transformation start scale
        destinationViewController.view.transform = CGAffineTransformMakeScale(0.05, 0.05);
    
        // Store original centre point of the destination view
        CGPoint originalCenter = destinationViewController.view.center;
        // Set center to start point of the button
        destinationViewController.view.center = self.originatingPoint;
    
        [UIView animateWithDuration:0.5
                              delay:0.0
                            options:UIViewAnimationOptionCurveEaseInOut
                         animations:^{
                             // Grow!
                             destinationViewController.view.transform = CGAffineTransformMakeScale(1.0, 1.0);
                             destinationViewController.view.center = originalCenter;
                         }
                         completion:^(BOOL finished){
                             [destinationViewController.view removeFromSuperview]; // remove from temp super view
                             [sourceViewController presentViewController:destinationViewController animated:NO completion:NULL]; // present VC
                         }];
    }
    

    【讨论】:

      猜你喜欢
      • 2011-03-25
      • 1970-01-01
      • 1970-01-01
      • 2016-10-11
      • 2011-06-18
      • 1970-01-01
      • 1970-01-01
      • 2012-05-15
      • 1970-01-01
      相关资源
      最近更新 更多