[10秒学会] - 自定义专场动画
2016-09-11 00:00
381 查看
第一步: 设置转场
第二步:代理
第三部:改变显示的内容 & frame 可任意定义
DCViewController *dcVC = [[DCViewController alloc]init]; [dcVC setModalPresentationStyle:UIModalPresentationCustom]; //自己定义专场动画 dcVC.transitioningDelegate = self.dcAnimator; //代理 [self presentViewController:dcVC animated:YES completion:^{ }];
第二步:代理
/** 改变弹出view的尺寸 */ - (UIPresentationController *)presentationControllerForPresentedViewController:(UIViewController *)presented presentingViewController:(UIViewController *)presenting sourceViewController:(UIViewController *)source{ _isPresent = YES; return [[DCPresentationController alloc]initWithPresentedViewController:presented presentingViewController:presenting]; } /** 改变弹出前的代理 */ - (id<UIViewControllerAnimatedTransitioning>)animationControllerForPresentedController:(UIViewController *)presented presentingController:(UIViewController *)presenting sourceController:(UIViewController *)source { _isPresent = NO; return self; } /** 弹出后的代理*/ - (id<UIViewControllerAnimatedTransitioning>)animationControllerForDismissedController:(UIViewController *)dismissed{ return self; } /** 弹出后的时间*/ - (NSTimeInterval)transitionDuration:(id<UIViewControllerContextTransitioning>)transitionContext{ return 1; } /** 显示的动画 */ - (void)animateTransition:(id<UIViewControllerContextTransitioning>)transitionContext{ //获取父view UIView *containerView = [transitionContext containerView]; if(_isPresent){ //显现 DCViewController *fromViewController = (DCViewController*)[transitionContext viewControllerForKey:UITransitionContextToViewControllerKey]; [containerView addSubview:fromViewController.view]; [UIView beginAnimations:nil context:nil]; [UIView setAnimationDuration:1]; [UIView setAnimationDelegate:self]; fromViewController.view.transform = CGAffineTransformMakeRotation(180 * (M_PI / 180.0f)); [UIView commitAnimations]; }else{ // 消失 } }
第三部:改变显示的内容 & frame 可任意定义
@implementation DCPresentationController - (void)containerViewWillLayoutSubviews { [super containerViewWillLayoutSubviews]; //添加蒙版 [self.containerView insertSubview:self.bgView atIndex:0]; self.bgView.backgroundColor = [UIColor colorWithWhite:0.8 alpha:0.5]; self.bgView.frame = self.containerView.bounds; self.presentedView.frame = CGRectMake(0, 0, 100, 100); } - (UIView *)bgView{ if(!_bgView){ _bgView = [[UIView alloc]init]; } return _bgView; }
相关文章推荐
- [10秒学会] - 动画组
- [10秒学会] - iOS <Photos/Photos.h>自定义相册
- iOS7教程系列:自定义导航转场动画以及更多
- JQuery学习笔记之自定义动画效果
- Android UI:看看Google官方自定义带旋转动画的ImageView-----RotateImageView怎么写(附 图片淡入淡...)
- 自定义转场动画--Swift3.0版本
- pdf.js 添加自定义loading动画
- (二十四)自定义动画框架
- iOS 自定义Tabbar实现push动画隐藏效果
- 自定义view实现阻尼效果的加载动画
- pushViewController自定义动画
- Phome开发历程分享——自定义Activity切换动画实现(12.17更新方法)
- iOS利用Runtime自定义控制器POP手势动画
- Android之自定义动画框架实现ScrollView滚动动画总结(雷惊风)
- android 自定义带增长动画和点击弹窗提示效果的柱状图
- Android中自定义Dialog对话框消除边距消除黑边框和显示动画
- VCTransitionsLibrary –自定义iOS交互式转场动画的库
- 关于ValueAnimation以及Interpolator +Drawable实现的自定义动画效果
- [置顶] 微信小程序自定义对话框+弹出和隐藏动画详解
- 自定义Dialog加载动画