YFCardTransitions 0.1.2

YFCardTransitions 0.1.2

测试已测试
Lang语言 Obj-CObjective C
许可 MIT
发布最后发布2015年1月

Yuri Ferretti 维护。




  • 作者:
  • yuriferretti

YFCardTransitions 是一系列自定义 UIViewController 过渡,旨在与 Tim Gleue 的优秀 TGLStackedViewController 一起使用。

安装

使用 CocoaPods,将以下行添加到您的 Podfile。

pod 'YFCardTransitions'

或者将源文件夹中的文件拖到您的项目中。

截图

Example

用法

首先,您必须创建一个子类 TGStackedViewController,它遵守 UIViewControllerTransitioningDelegate 协议,并添加两个属性,这两个属性将负责过渡。

@interface YFCardCollectionViewController () <UIViewControllerTransitioningDelegate>

@property (strong, nonatomic) YFCardPickTranstion           *cardPickTransition;
@property (strong, nonatomic) YFDragDownToDismissTransition *dragDownToDismissTransition;

@end

您必须将 YFCardPickTransition 的 duaration 属性设置为您想要的值,并将 cardTopReveal 设置为与 TGLStackedLayouttopReveal 属性相同的值。

- (YFCardPickTranstion *)cardPickTransition {
    if (!_cardPickTransition) {
        _cardPickTransition = [YFCardPickTranstion new];
        _cardPickTransition.duration = 0.5;
        _cardPickTransition.cardTopReveal = self.stackedLayout.topReveal;
    }
    return _cardPickTransition;
}

同时创建一个 UICollectionViewCell 子类,您将使用 TGLStackedViewController 子类。

UICollectionViewDelegate 协议方法 collectionView:didSelectItemAtIndexPath: 中,您应该获取所选单元格引用的 frame 和截图。

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {

    UICollectionViewLayoutAttributes *attributes = [collectionView layoutAttributesForItemAtIndexPath:indexPath];
    CGRect referenceFrame = [collectionView convertRect:attributes.frame toView:collectionView.superview];

    self.cardPickTransition.referenceFrame = referenceFrame;

    CardCollectionViewCell *cell = (CardCollectionViewCell *)[collectionView cellForItemAtIndexPath:indexPath];
    UIView *snapshotView = [cell snapshotViewAfterScreenUpdates:YES];

    self.cardPickTransition.movingCardSnapshot = snapshotView;

    self.selectedCardColor = cell.imageView.tintColor;

    [self performSegueWithIdentifier:@"showDetail" sender:nil];

}

实现 UIViewControllerTransitioningDelegate 方法

- (id<UIViewControllerAnimatedTransitioning>)animationControllerForPresentedController:(UIViewController *)presented presentingController:(UIViewController *)presenting sourceController:(UIViewController *)source {

    return self.cardPickTransition;
}

- (id<UIViewControllerAnimatedTransitioning>)animationControllerForDismissedController:(UIViewController *)dismissed {
    return  self.dragDownToDismissTransition;
}

- (id<UIViewControllerInteractiveTransitioning>)interactionControllerForDismissal:(id<UIViewControllerAnimatedTransitioning>)animator {

    return self.dragDownToDismissTransition;
}

将呈现的视图控制器连接到 YFDragDownToDismissTransition 实例

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {

    ViewController *vc = segue.destinationViewController;
    [self.dragDownToDismissTransition wireToViewController:vc];
    vc.transitioningDelegate = self;
    vc.modalPresentationStyle = UIModalPresentationCustom;
}

这个存储库中提供了一个完整的示例。

要求

  • iOS 7 或更高版本
  • ARC

致谢

作者

许可

MIT 许可证

版权所有 © 2015 Yuri Ferretti

以下各项授予copyright notice free of charge to anyone取得本软件和相关文档文件(“软件”)的副本(以下简称“软件”),在不限制的情况下,包括不受限制使用、复制、修改、合并、发布、分发、再许可和/或销售软件的副本的权利,并允许将软件提供给其他人,以供其使用,同时受以下条件的约束:

上述版权声明和本许可声明应包含在软件的所有副本或主要部分中。

本软件按“现状”提供,不提供任何形式的保证,无论是明确的还是隐含的,包括但不限于适销性、适用于特定目的或非侵权性。在任何情况下,作者或版权所有者均不对由此产生的任何索赔、损害或其他责任承担责任,无论是因为合同、侵权或其他,包括但不限于与软件的使用、修改、分发或其他形式的处理有关的行为。