ZOZolaZoomTransition 1.0.1

ZOZolaZoomTransition 1.0.1

测试已测试
语言语言 Obj-CObjective C
许可 MIT
发布最新发布2016年11月

Charles Scalesse 维护。



  • Charles Scalesse

ZOZolaZoomTransition 是一个缩放过渡动画,它将整个视图层次结构动画化。它在 Zola iOS 应用程序 中得到了广泛的应用。

它的样子是这样的

Zola for iPad

示例

ZOZolaZoomTransition 包含一个功能齐全的演示项目。以下是基本实现步骤。假设一个典型的“主-详细”场景,其中“主”控制器包含一个 UICollectionView,当点击一个单元格时,“详细”控制器被推入堆栈。过渡动画将从所选单元格的 imageView 到 detailController 的 imageView 播放。

  1. 实现这个 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;
    }
  2. 实现两个必需的 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 数组中的补充视图,这些视图将在动画的其他视图之上绘制和动画化。补充视图的两个常见用例是:

  1. 绘制位于目标视图之上,但不是其子视图的视图。
  2. 绘制当过渡开始时被屏幕边缘剪切的视图。因此,在动画过程中看起来被截断。

以下是一个示例。以下单元格行在用户点击最左边的单元格时被屏幕底部剪裁。以下是过渡过程中的两个截图:

没有补充视图

Without supplementary views

带有补充视图:(“组礼品”横幅和右侧的两个单元格已添加为补充视图,因此它们位于动画之上)

With supplementary views

应用扩展

ZOZolaZoomTransition 使用了 UIApplicationbeginIgnoringInteractionEventsendIgnoringInteractionEvents 方法,这些方法在应用扩展内部不可用。要在扩展中使用 ZOZolaZoomTransition,在扩展目标的构建设置中定义以下预处理器宏:ZO_APP_EXTENSIONS=1

Preprocessor macro for app extensions

设置说明

使用CocoaPods安装,请将以下内容添加到您的Podfile中:

platform :ios, '7.0'
pod 'ZOZolaZoomTransition', '~> 1.0.0'

或手动添加ZOZolaZoomTransition.hZOZolaZoomTransition.m到您的项目中。

限制

  • ZOZolaZoomTransition目前仅适用于UINavigationController过渡。我们还需要添加对模态过渡的支持,理想状态下不应该改变API。欢迎提交pull请求!

要求

ZOZolaZoomTransition需要iOS 7.0或更高版本。

许可证

ZOZolaZoomTransition在MIT许可证下可用。详见LICENSE文件以获取更多信息。