ios - 当您点击 iOS 主屏幕上的应用程序图标时,如何制作应用程序启动之类的动画?

标签 ios objective-c ios7 core-animation uicollectionview

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

我正在使用 iOS 7 新 api 进行 View Controller 转换。 我正在使用父 Collection View Controller 快照来实现适当的动画。 但我仍然没有足够了解当时实际发生的动画?

最佳答案

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

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

- (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;
    }];
}

关于ios - 当您点击 iOS 主屏幕上的应用程序图标时,如何制作应用程序启动之类的动画?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25452422/

相关文章:

iphone - 自动释放和属性

ios - Objective-C 中的委托(delegate)

ios - 当我的应用程序在 iPad 上运行时屏幕始终亮着

ios - 如何从 ALAsset 对象获取全景图

ios - native Controller 的 preferredStatusBarStyle

ios - 无法让 CALayer 在 UIView 中显示

ios - 如何在不打开 MailComposer 或 objective-c 中的新 View 的情况下通过代码发送邮件

iphone - 当 super View 不同时,如何在 iphone 中为 View 的帧更改设置动画......?

iphone - "cellForRowAtIndexPath:"中 indexPath.section 的奇怪行为

iphone - 将对象存储到 NSMutableArray