我想做一些类似于 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/