Reputation: 1378
I wants to do animation something similar to app launch on the ios home screen. Like the whole collection view goes to scale up and the launched app covered the whole screen.
I am using the iOS 7 new api for viewcontroller transitions. And I am using the parent collection viewcontroller snapshot to appropriate animation. But still I am not getting enough like what animation is actually is happening at that time?
Upvotes: 0
Views: 983
Reputation: 22701
To get the performance and look you want, you may have to perform transforms on the view layers.
I put up a little demo on GitHub, but the relevant code is below.
- (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;
}];
}
Upvotes: 1
Reputation: 6244
You need to use custom segues.
This tutorial should help you and below is the code excerpt.
- (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
}];
}
Upvotes: 0