当您点击iOS主屏幕上的应用程序图标时,如何进行应用程序启动等动画?

时间:2014-08-22 17:20:33

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

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

我正在使用iOS 7新的api进行viewcontroller转换。 我正在使用父集合viewcontroller快照来适当的动画。 但是我还没有达到那个时候动画实际发生的那么多吗?

2 个答案:

答案 0 :(得分:1)

要获得所需的性能和效果,您可能必须在视图图层上执行变换。

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

答案 1 :(得分:0)

您需要使用自定义segues。

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