【发布时间】:2014-10-16 15:02:40
【问题描述】:
我想做一些类似于在 ios 主屏幕上启动应用程序的动画。就像整个集合视图放大一样,启动的应用程序覆盖了整个屏幕。
我正在使用 iOS 7 的新 api 进行视图控制器转换。 我正在使用父集合视图控制器快照来制作适当的动画。 但是我仍然对当时正在发生的动画感到不够了解?
【问题讨论】:
标签: ios objective-c ios7 core-animation uicollectionview
我想做一些类似于在 ios 主屏幕上启动应用程序的动画。就像整个集合视图放大一样,启动的应用程序覆盖了整个屏幕。
我正在使用 iOS 7 的新 api 进行视图控制器转换。 我正在使用父集合视图控制器快照来制作适当的动画。 但是我仍然对当时正在发生的动画感到不够了解?
【问题讨论】:
标签: ios objective-c ios7 core-animation uicollectionview
要获得所需的性能和外观,您可能必须对视图层执行转换。
我在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;
}];
}
【讨论】:
您需要使用自定义转场。
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
}];
}
【讨论】: