快速实现控制器的转场和View的快速popover显示,并支持自定义动画、手势退场
pod 'TLTransitions', '~> 1.5.1'
TLTransitions
版本问题这可能是本地的CocoaPods仓库列表没有更新导致的。
运行以下命令更新本地的CocoaPods仓库列表:
pod repo update
然后通过以下命令查询
pod search TLTransitions
如果仍然查询不到最新版本,可以删除本地仓库重新安装
sudo rm -rf ~/.cocoapods/repos/master pod setup
让繁琐的个性化控制器的转场(present/pop)和视图弹窗实现,变的简单快速(一句代码或几行即可搞定),并支持动画的自定义,支持通过手势转场(dismiss/pop)
UIViewControllerTransitioningDelegate
,UINavigationControllerDelegate
,UIViewControllerAnimatedTransitioning
UIPresentationController
TLTransition
类的API,只要一行代码即可将一个已有的View进行显示,使用如下(更多使用见TLTransition.h
中的API 或 Demo))// popView是一个用户自定义的视图,并且已经设置好布局
[TLTransition showView:popView popType:TLPopTypeAlert];
// 实时更新view的size ,显示后也可以更新
- (void)updateContentSize;
// 使用
CGRect rect = _bView.bounds;
rect.size.height += 1;
_bView.bounds = rect;
[_transition updateContentSize];
/**
* 隐藏popView
* 如果TLTransition没有被引用,则在隐藏后会自动释放
* 如果popView没有被引用,在隐藏后也会自动释放
*/
- (void)dismiss;
// 使用
[_transition dismiss];
UIViewController+Transitioning
和遵守TLTLAnimatorProtocol
协议的Animator
类系统原生转场动画
(非自定义转场)、Swipe系列
、CATransition系列动画
、Cunstom Block模式
、案例锦集
Swipe系列
、CATransition系列
、Cunstom模式
、案例锦集
非Cunstom模式
)
只要基于TLTLAnimatorProtocol
协议即可,具体实现可参考模版TLAnimatorTemplate
里面有一些思路与注意事项UIViewController+Transitioning.h
中的API 或 Demo)
可以一步实现,也可以分步实现
a. 分步实现(建议使用,更灵活、多样化、统一化):
更多API的使用见demo
TLSecondViewController *vc = [[TLSecondViewController alloc] init];
vc.disableInteractivePopGestureRecognizer = YES; // 关闭手势
// 1.创建动画管理者
TLCATransitonAnimator *animator;
animator = [TLCATransitonAnimator animatorWithTransitionType:transitionType
direction:direction
transitionTypeOfDismiss:transitionTypeOfDismiss
directionOfDismiss:dismissDirection];
animator.transitionDuration = 3.0; // 动画时间
// 调用API转场
// push(直接使用self发起API调用)
[self pushViewController:vc animator:animator];
/** present
[self presentViewController:vc animator:animator completion:^{
// 完成回调
}];
*/
b. 一步实现:
更多API的使用见demo
TLSecondViewController *vc = [[TLSecondViewController alloc] init];
// vc.disableInteractivePopGestureRecognizer = YES; // 关闭侧滑pop手势
// push (直接使用self发起API调用)
[self pushViewController: vc
swipeType: TLSwipeTypeInAndOut
pushDirection: TLDirectionToRight
popDirection: TLDirectionToRight];
/** present
[self presentViewController:vc
swipeType: TLSwipeTypeInAndOut
presentDirection:TLDirectionToRight
dismissDirection:TLDirectionToRight
completion:^ {
// 完成回调
}];
*/
- hidesBottomBarWhenPushed
隐藏bottom bar 或 tabbar时,bar与view的转场动画不协调的情况(如下图所示)
happying
同学提出,并给出他的处理方案
toVC.hidesBottomBarWhenPushed = YES
。(只在特殊情况下需要处理)- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
if (显示条件) {
self.tabBarController.tabBar.hidden = NO; // 如果是pop回来的,且需要显示bar,就手动将其显示
}
}
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
UIViewController *toVc = [UIViewController new];
toVc.view.backgroundColor = [UIColor redColor];
toVc.hidesBottomBarWhenPushed = NO; // 设置为NO
self.tabBarController.tabBar.hidden = YES; // push前手动隐藏bar
TLSwipeAnimator *anm = [TLSwipeAnimator animatorWithSwipeType:TLSwipeTypeInAndOut pushDirection:TLDirectionToTop popDirection:TLDirectionToBottom];
[self pushViewController:toVc animator:anm];
}