控制器之间跳转实现转场动画,动画控制器概念
/cms/uploads/soft/131224/4673-131224114628.zip |
- [UIView animateKeyframesWithDuration:duration delay:delay
- options:options animations:^{
- [UIView addKeyframeWithRelativeStartTime:0.0
- relativeDuration:0.5 animations:^{
- //第一帧要执行的动画
- }];
- [UIView addKeyframeWithRelativeStartTime:0.5
- relativeDuration:0.5 animations:^{
- //第二帧要执行的动画
- }];
- } completion:^(BOOL finished) {
- //动画结束后执行的代码块
- }];
- [UIView addKeyframeWithRelativeStartTime:0.0
- relativeDuration:0.15 animations:^{
- //顺时针旋转90度
- snapshot.transform = CGAffineTransformMakeRotation(M_PI *
- -1.5);
- }];
- [UIView addKeyframeWithRelativeStartTime:0.15
- relativeDuration:0.10 animations:^{
- //180度
- snapshot.transform = CGAffineTransformMakeRotation(M_PI *
- 1.0);
- }];
- [UIView addKeyframeWithRelativeStartTime:0.25
- relativeDuration:0.20 animations:^{
- //摆过中点,225度
- snapshot.transform = CGAffineTransformMakeRotation(M_PI *
- 1.3);
- }];
- [UIView addKeyframeWithRelativeStartTime:0.45
- relativeDuration:0.20 animations:^{
- //再摆回来,140度
- snapshot.transform = CGAffineTransformMakeRotation(M_PI *
- 0.8);
- }];
- [UIView addKeyframeWithRelativeStartTime:0.65
- relativeDuration:0.35 animations:^{
- //旋转后掉落
- //最后一步,视图淡出并消失
- CGAffineTransform shift =
- CGAffineTransformMakeTranslation(180.0, 0.0);
- CGAffineTransform rotate =
- CGAffineTransformMakeRotation(M_PI * 0.3);
- snapshot.transform = CGAffineTransformConcat(shift,
- rotate);
- _coverView.alpha = 0.0;
- }];
- [UIView animateWithDuration:duration delay:delay
- usingSpringWithDamping:damping initialSpringVelocity:velocity
- options:options animations:^{
- //这里书写动画相关代码
- } completion:^(BOOL finished) {
- //动画结束后执行的代码块
- }];
- -(void)animateTransition:
- (id)transitionContext {
- //获取容器视图引用
- UIView *containerView = [transitionContext
- containerView];
- UIViewController *fromViewController = [transitionContext
- viewControllerForKey:UITransitionContextFromViewControllerKey
- ];
- UIViewController *toViewController = [transitionContext
- viewControllerForKey:UITransitionContextToViewControllerKey];
- if (self.type == AnimationTypePresent) {
- //插入“to”视图,初始缩放值为0.0
- toViewController.view.transform =
- CGAffineTransformMakeScale(0.0, 0.0);
- [containerView insertSubview:toViewController.view
- aboveSubview:fromViewController.view];
- //缩放“to”视图为想要的效果
- [UIView animateWithDuration:[self
- transitionDuration:transitionContext] animations:^{
- toViewController.view.transform =
- CGAffineTransformMakeScale(1.0, 1.0);
- } completion:^(BOOL finished) {
- [transitionContext completeTransition:YES];
- }];
- } else if (self.type == AnimationTypeDismiss) {
- //插入“to”视图
- [containerView insertSubview:toViewController.view
- belowSubview:fromViewController.view];
- //缩小“from”视图,直到其消失
- [UIView animateWithDuration:[self
- transitionDuration:transitionContext] animations:^{
- fromViewController.view.transform =
- CGAffineTransformMakeScale(0.0, 0.0);
- } completion:^(BOOL finished) {
- [transitionContext completeTransition:YES];
- }];
- }
- }
- -(NSTimeInterval)transitionDuration:
- (id)transitionContext {
- return 0.4;
- }
- -(id)
- animationControllerForPresentedController:(UIViewController
- *)presented presentingController:(UIViewController
- *)presenting sourceController:(UIViewController *)source {
- modalAnimationController.type = AnimationTypePresent;
- return modalAnimationController;
- }
- -(id)
- animationControllerForDismissedController:(UIViewController
- *)dismissed {
- modalAnimationController.type = AnimationTypeDismiss;
- return modalAnimationController;
- }
- OptionsViewController *modal = [[OptionsViewController alloc]
- initWithNibName:@"OptionsViewController" bundle:[NSBundle
- mainBundle]];
- modal.transitioningDelegate = self;
- modal.modalPresentationStyle = UIModalPresentationCustom;
- [self presentViewController:modal animated:YES
- completion:nil];
- @interface UIPercentDrivenInteractiveTransition : NSObject
- @property (readonly) CGFloat duration;
- @property (readonly) CGFloat percentComplete;
- @property (nonatomic,assign) CGFloat completionSpeed;
- @property (nonatomic,assign) UIViewAnimationCurve
- completionCurve;
- - (void)updateInteractiveTransition:(CGFloat)percentComplete;
- - (void)cancelInteractiveTransition;
- - (void)finishInteractiveTransition;
- -(void)handlePinch:(UIPinchGestureRecognizer *)pinch {
- CGFloat scale = pinch.scale;
- switch (pinch.state) {
- case UIGestureRecognizerStateBegan: {
- _startScale = scale;
- self.interactive = YES;
- [self.navigationController
- popViewControllerAnimated:YES];
- break;
- }
- case UIGestureRecognizerStateChanged: {
- CGFloat percent = (1.0 - scale/_startScale);
- [self updateInteractiveTransition:(percent < 0.0) ?
- 0.0 : percent];
- break;
- }
- case UIGestureRecognizerStateEnded: {
- CGFloat percent = (1.0 - scale/_startScale);
- BOOL cancelled = ([pinch velocity] < 5.0 && percent
- <= 0.3);
- if (cancelled) [self cancelInteractiveTransition];
- else [self finishInteractiveTransition];
- break;
- }
- case UIGestureRecognizerStateCancelled: {
- CGFloat percent = (1.0 - scale/_startScale);
- BOOL cancelled = ([pinch velocity] < 5.0 && percent
- <= 0.3);
- if (cancelled) [self cancelInteractiveTransition];
- else [self finishInteractiveTransition];
- break;
- }
- }
- }
- -(void)startInteractiveTransition:
- (id)transitionContext {
- //获取transitionContext对象的引用
- _context = transitionContext;
- //获取容器视图引用
- UIView *containerView = [transitionContext
- containerView];
- UIViewController *fromViewController = [transitionContext
- viewControllerForKey:UITransitionContextFromViewControllerKey
- ];
- UIViewController *toViewController = [transitionContext
- viewControllerForKey:UITransitionContextToViewControllerKey];
- //插入“to”视图
- toViewController.view.frame = [transitionContext
- finalFrameForViewController:toViewController];
- [containerView insertSubview:toViewController.view
- belowSubview:fromViewController.view];
- //保留需要缩?小的视图的引用
- _transitioningView = fromViewController.view;
- }
- -(void)updateWithPercent:(CGFloat)percent {
- CGFloat scale = fabsf(percent-1.0);
- _transitioningView.transform =
- CGAffineTransformMakeScale(scale, scale);
- [_context updateInteractiveTransition:percent];
- }
- -(void)end:(BOOL)cancelled {
- if (cancelled) {
- [UIView animateWithDuration:_completionSpeed
- animations:^{
- _transitioningView.transform =
- CGAffineTransformMakeScale(1.0, 1.0);
- } completion:^(BOOL finished) {
- [_context cancelInteractiveTransition];
- [_context completeTransition:NO];
- }];
- } else {
- [UIView animateWithDuration:_completionSpeed
- animations:^{
- _transitioningView.transform =
- CGAffineTransformMakeScale(0.0, 0.0);
- } completion:^(BOOL finished) {
- [_context finishInteractiveTransition];
- [_context completeTransition:YES];
- }];
- }
- }
- [UIView performWithoutAnimation:^{
- //确保不执行动画
- }];
- CollectionViewController *VC = [[CollectionViewController
- alloc] initWithCollectionViewLayout:flowLayout];
- VC.title = @"Mini Apples";
- VC.useLayoutToLayoutNavigationTransitions = YES;
- [self.navigationController pushViewController:VC
- animated:YES];
- [self.transitionCoordinator
- animateAlongsideTransition:^(id<uiviewcontrollertransitioncoo < span="">
- rdinatorContext> context) {
- //要执行的动画
- }
- completion:^(id
- context) {
- //动画结束后执行的代码块
- }];
- [self.transitionCoordinator
- notifyWhenInteractionEndsUsingBlock:^(id<uiviewcontrollertran < span="">
- sitionCoordinatorContext> context) {
- //动画结束后执?行的代码块
- }];
- [view snapshotViewAfterScreenUpdates:NO];
- [view snapshotViewAfterScreenUpdates:YES];
- [view setAlpha:0.0];
/cms/uploads/soft/131224/4673-131224114628.zip |
控制器之间跳转实现转场动画,动画控制器概念相关推荐
- (0030) iOS 开发之跳转之转场动画
demo: 1 iOS ~ ViewController的Push,Pop和Present,Dismiss转场动画 // http://blog.csdn.net/zhangao0086/artic ...
- 去除警告,打电话,发信息,应用程序之间跳转,打印沙盒路径,字符串名字转换方法,包装导航控制器等的代码...
从偏好设置中读取值: 打电话代码: 发信息代码: 打印沙盒路径代码: 应用程序之间跳转代码: 跳转到苹果商店代码: 去除警告代码: 根据字符串名称转换成相对应方法的代码: #import " ...
- IOS开发控制器之间传值的几种小方法
在IOS开发中或面试中,经常会遇到,两个或者多个控制器之间传值的问题 ,总结的集中方法仅供参考! 问题 :将B控制器中的textField 输入内容,传到A控制器中的label上显示出来,如何传值? ...
- iOS开发之控制器之间传值
2019独角兽企业重金招聘Python工程师标准>>> 多个界面之间的跳转,免不了要进行数据传递,可以是顺向的,也可以是逆向的.android中activity之间数据传递是用sta ...
- 和12岁小同志搞创客开发:两个控制器之间如何实现通信?
目录 1.有线通信 2.无线通信 3.串口点灯 机缘巧合在网上认识一位12岁小同志,从零开始系统辅导其创客开发思维和技巧. 项目专栏:https://blog.csdn.net/m0_38106 ...
- 两种控制器的跳转与回跳
第一种:用于任何控制器的跳转, - (void)presentViewController:(UIViewController *)viewControllerToPresent animated: ...
- 在AngularJS控制器之间共享数据
本文翻译自:Share data between AngularJS controllers I'm trying to share data across controllers. 我正在尝试跨控制 ...
- 在视图控制器之间传递数据
我是iOS和Objective-C以及整个MVC范例的新手,但我坚持以下几点: 我有一个充当数据输入表单的视图,我想给用户选择多个产品的选项. 这些产品在另一个带有UITableViewControl ...
- angularJS--多个控制器之间的数据共享
为了在控制器之间共享数据,需要在服务中添加一个用来储存用户名的方法.记住,服务在 应用的生命周期内是单例模式的,因此可以将用户名安全地储存在其中. <!DOCTYPE html> < ...
最新文章
- 《Windows Communication Foundation之旅》系列之一
- 用c语言 简单实现JAVA里面的ArryList 功能,实现内存自动扩展
- OAuth2解决什么问题
- kotlin学习之泛型(十四)
- 各种排序笔记---基于非比较排序部分
- mysql ip to int_ip网段转换程序(把ip地址转换成相对就的整数)
- 【转】WCF与Web API 区别(应用场景)
- 风变编程python网址_风变编程:职场学习Python的重要性
- 初中参观机器人博物馆的作文_导览机器人为参观者带来更佳的观展体验
- cisco思科模拟器中断translating域名翻译快捷键
- (构造笔记)GRASP学习心得
- DLL注入 + VEH 的方式处理异常
- Python 构建 Random Forest 和 XGBoost
- 前端常识:常见显示器屏幕分辨率
- C#图形窗口的几种边框样式,固定大小,及可调节大小等样式
- log4j2 2.14.0之前的版本出现重大漏洞
- remosaic插值算法_手机镜头像素:硬件直出和插值有啥区别?
- 面向对象之猫抓老鼠小游戏
- 2015小米校招【研发类】面试真题经验分享
- houdini mops