我想制作类似于在iOS主屏幕上启动应用程序的动画。就像整个收藏集视图会按比例放大一样,启动的应用程序会覆盖整个屏幕。

我正在使用iOS 7新API进行ViewController过渡。
而且我正在使用父集合viewcontroller快照来制作适当的动画。
但是,我仍然还不够像当时正在发生的动画那样?

最佳答案

为了获得所需的性能和外观,您可能必须在视图层上执行转换。

我在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;
    }];
}

08-05 23:45