ZOZolaZoomTransition
是一个缩放过渡动画,它将整个视图层次结构动画化。它在 Zola iOS 应用程序 中得到了广泛的应用。
它的样子是这样的
ZOZolaZoomTransition
包含一个功能齐全的演示项目。以下是基本实现步骤。假设一个典型的“主-详细”场景,其中“主”控制器包含一个 UICollectionView
,当点击一个单元格时,“详细”控制器被推入堆栈。过渡动画将从所选单元格的 imageView
到 detailController 的 imageView
播放。
实现这个 UINavigationControllerDelegate
方法,并返回一个 ZOZolaZoomTransition
实例
- (id <UIViewControllerAnimatedTransitioning>)navigationController:(UINavigationController *)navigationController
animationControllerForOperation:(UINavigationControllerOperation)operation
fromViewController:(UIViewController *)fromVC
toViewController:(UIViewController *)toVC {
// Determine if we're presenting or dismissing
ZOTransitionType type = (fromVC == self) ? ZOTransitionTypePresenting : ZOTransitionTypeDismissing;
// Create a transition instance with the selected cell's imageView as the target view
ZOZolaZoomTransition *zoomTransition = [ZOZolaZoomTransition transitionFromView:_selectedCell.imageView
type:type
duration:0.5
delegate:self];
return zoomTransition;
}
实现两个必需的 ZOZolaZoomTransitionDelegate
方法,为目标的视图提供起始和结束帧(请参阅 ZOZolaZolaZoomTransition.h 以获得详细的文档)。必须相对于提供的 relativeView
返回帧
- (CGRect)zolaZoomTransition:(ZOZolaZoomTransition *)zoomTransition
startingFrameForView:(UIView *)targetView
relativeToView:(UIView *)relativeView
fromViewController:(UIViewController *)fromViewController
toViewController:(UIViewController *)toViewController {
if (fromViewController == self) {
// We're pushing to the detail controller. The starting frame is taken from the selected cell's imageView.
return [_selectedCell.imageView convertRect:_selectedCell.imageView.bounds toView:relativeView];
} else if ([fromViewController isKindOfClass:[ZODetailViewController class]]) {
// We're popping back to this master controller. The starting frame is taken from the detailController's imageView.
ZODetailViewController *detailController = (ZODetailViewController *)fromViewController;
return [detailController.imageView convertRect:detailController.imageView.bounds toView:relativeView];
}
return CGRectZero;
}
- (CGRect)zolaZoomTransition:(ZOZolaZoomTransition *)zoomTransition
finishingFrameForView:(UIView *)targetView
relativeToView:(UIView *)relativeView
fromViewController:(UIViewController *)fromViewComtroller
toViewController:(UIViewController *)toViewController {
if (fromViewComtroller == self) {
// We're pushing to the detail controller. The finishing frame is taken from the detailController's imageView.
ZODetailViewController *detailController = (ZODetailViewController *)toViewController;
return [detailController.imageView convertRect:detailController.imageView.bounds toView:relativeView];
} else if ([fromViewComtroller isKindOfClass:[ZODetailViewController class]]) {
// We're popping back to this master controller. The finishing frame is taken from the selected cell's imageView.
return [_selectedCell.imageView convertRect:_selectedCell.imageView.bounds toView:relativeView];
}
return CGRectZero;
}
ZOZolaZoomTransition
支持 optional 数组中的补充视图,这些视图将在动画的其他视图之上绘制和动画化。补充视图的两个常见用例是:
以下是一个示例。以下单元格行在用户点击最左边的单元格时被屏幕底部剪裁。以下是过渡过程中的两个截图:
没有补充视图
带有补充视图:(“组礼品”横幅和右侧的两个单元格已添加为补充视图,因此它们位于动画之上)
ZOZolaZoomTransition
使用了 UIApplication
的 beginIgnoringInteractionEvents
和 endIgnoringInteractionEvents
方法,这些方法在应用扩展内部不可用。要在扩展中使用 ZOZolaZoomTransition
,在扩展目标的构建设置中定义以下预处理器宏:ZO_APP_EXTENSIONS=1
使用CocoaPods安装,请将以下内容添加到您的Podfile中:
platform :ios, '7.0'
pod 'ZOZolaZoomTransition', '~> 1.0.0'
或手动添加ZOZolaZoomTransition.h
和ZOZolaZoomTransition.m
到您的项目中。
ZOZolaZoomTransition
目前仅适用于UINavigationController
过渡。我们还需要添加对模态过渡的支持,理想状态下不应该改变API。欢迎提交pull请求!ZOZolaZoomTransition
需要iOS 7.0或更高版本。
ZOZolaZoomTransition
在MIT许可证下可用。详见LICENSE
文件以获取更多信息。