转场动画

  1 /*
  2  CATransaction 转场动画 可以切换视图 视图控制器
  3  Type 转场动画 的动画效果
  4  subtype 转场动画效果方向
  5
  6
  7 */
  8 #import "ViewController.h"
  9 #import "NextViewController.h"
 10
 11 typedef enum Direction{
 12     Right = 0,
 13     Left,
 14 } Direction;
 15
 16 @interface ViewController ()
 17 {
 18     NSArray *imageList;
 19     UIImageView *showImage;
 20     int index;
 21 }
 22 @end
 23
 24 @implementation ViewController
 25
 26 - (void)viewDidLoad {
 27     [super viewDidLoad];
 28     self.view.backgroundColor = [UIColor redColor];
 29
 30     imageList = @[@"1",@"8fac777" ];
 31     showImage = [[UIImageView alloc]initWithFrame:[UIScreen mainScreen].bounds];
 32     showImage.image = [UIImage imageNamed:@"1"];
 33     [self.view addSubview:showImage];
 34     showImage.userInteractionEnabled = YES;
 35     UISwipeGestureRecognizer *swipe = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(RightswipeAction)];
 36     swipe.direction = UISwipeGestureRecognizerDirectionRight;
 37
 38     [self.view addGestureRecognizer:swipe];
 39
 40     UISwipeGestureRecognizer *leftSwipe = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(leftSwipeAction)];
 41     swipe.direction = UISwipeGestureRecognizerDirectionLeft;
 42
 43     [self.view addGestureRecognizer:leftSwipe];
 44
 45     UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(longPressAction:)];
 46     [self.view addGestureRecognizer:longPress];
 47 }
 48
 49
 50 #pragma mark--------跳转到下一个页面-----
 51 - (void)longPressAction:(UILongPressGestureRecognizer *)sender{
 52     if (sender.state == UIGestureRecognizerStateBegan) {
 53         NextViewController *next = [[NextViewController alloc]init];
 54         CATransition *animation = [CATransition animation];
 55         animation.type = @"rippleEffect";
 56         animation.subtype = kCATransitionFromRight;
 57         animation.duration = 1;
 58
 59         [self.navigationController pushViewController:next animated:NO];
 60     }
 61
 62
 63 }
 64
 65 - (void)didCHangeImageWithDirection:(Duration)direction{
 66
 67     index = direction == Right ? [self countRelease] : [self countAdd];
 68
 69
 70     CATransition *transition = [CATransition animation];
 71     transition.type = direction == Right ? @"cube" : @"rippleEffect";
 72     transition.subtype = direction == Right ? kCATransitionFromRight : kCATransitionFromLeft;
 73     transition.duration = 1;
 74     [showImage.layer addAnimation:transition forKey:nil];
 75
 76     showImage.image = [UIImage imageNamed:imageList[index]];
 77 }
 78
 79 #pragma mark---------向左滑动图片加---------
 80 //需要 通过方向 判断 是自加 还是自减 把计算号的值 赋给 全局变量
 81 - (int)countAdd{
 82     index ++;
 83
 84 //    如果超出了 图片数组的元素 修复成0 没有超出 返回增加后的值
 85     return index = index >= imageList.count ? 0 : index;
 86
 87 }
 88 #pragma mark---------向右滑动图片减---------
 89 - (int)countRelease{
 90     index --;
 91     return index<0 ? (int)imageList.count-1:index;
 92 }
 93
 94 - (void)RightswipeAction{
 95     [self didCHangeImageWithDirection:Right];
 96
 97 }
 98
 99 - (void)leftSwipeAction{
100     [self didCHangeImageWithDirection:Left];
101
102 }
时间: 2024-08-01 22:37:07

转场动画的相关文章

iOS 自定义转场动画篇

前言: 自定义转场动画其实并不难, 关键在于能够明白思路, 也就是操作步骤. 本篇博客主要以present转场动画为例, 进行分析, 操作, 如有错误欢迎简信与我交流. 不进行修改的话, presentViewController:animated:completion:相信这个方法很多人都是用过, 称作模态推出界面, 默认都是从屏幕下方推出新的控制器. 自定义的目的就是为了修改固定的推出方式, 同时加上你想要的动画. 一个关键的概念: UIViewControllerAnimatedTrans

CATransition转场动画

背景: 最近在温习动画,分享个简单系统的转场动画 viewcontroller *VC=[self.storyboard instantiateViewControllerWithIdentifier:@"StoryboardID"];    //类方法创建一个动画    CATransition *animationOne=[CATransition animation];    //动画持续时间    animationOne.duration=1;    //动画效果    [a

CATransition-转场动画

CAAnimation的子类,用于做转场动画,能够为层提供移出屏幕和移入屏幕的动画效果.iOS比Mac OS X的转场动画效果少一点 UINavigationController就是通过CATransition实现了将控制器的视图推入屏幕的动画效果 属性解析: type:动画过渡类型 subtype:动画过渡方向 startProgress:动画起点(在整体动画的百分比) endProgress:动画终点(在整体动画的百分比) 类型字符串 效果说明 关键字 方向 fade 交叉淡化过渡 YES

图片浏览(CATransition)转场动画

Main.storyboard ViewController.m // //  ViewController.m //  8A04.图片浏览(转场动画) // //  Created by huan on 16/2/4. //  Copyright © 2016年 huanxi. All rights reserved. // #import "ViewController.h" #define AnimationDuration 2 @interface ViewController

使用转场动画构造侧滑

原理:转场动画push pop 菜单控制器做成左边不透明一部分右边透明,代码里复制了之前控制器的视图会在这里显示 菜单和菜单详情是用的两个不同的转场动画实现的 效果图 demo链接:http://pan.baidu.com/s/1c0TaHDu

iOS:UIView的block函数实现转场动画---双视图

使用UIView动画函数实现转场动画——双视图 + (void)transitionFromView:(UIView *)fromView toView:(UIView *)toView duration:(NSTimeInterval)duration options:(UIViewAnimationOptions)options completion:(void (^)(BOOL finished))completion; 参数说明: –duration:动画的持续时间 –options:转

iOS:核心动画之转场动画CATransition

转场动画——CATransition CATransition是CAAnimation的子类,用于做转场动画,能够为层提供移出屏幕和移入屏幕的动画效果.iOS比Mac OS X的转场动画效果少一点 UINavigationController就是通过CATransition实现了将控制器的视图推入屏幕的动画效果 动画属性: –type:动画过渡类型 –subtype:动画过渡方向 –startProgress:动画起点(在整体动画的百分比) –endProgress:动画终点(在整体动画的百分比

Android的Fragment的自定义转场动画

Fragment间转场可以使用setTransition()来设置系统默认的转场动画,也可以使用setCustomAnimations()方法来自定义转场动画. getFragmentManager().beginTransaction() //An optional name for this back stack state, or null.addToBackStack()方法的参数如前面所说也可以为null .addToBackStack(null)//将替换的前一个事务添加的有Acti

实现Activity间的共享控件转场动画

实现Activity间的共享控件转场动画 字数1210 阅读1936 评论9 喜欢35 Lollipop中有shared_element可以进行元素在activity之间进行共享,网上已经有很多介绍了,然而目前还有大量的kitkat设备,所以说啊,兼容更重要. 如下的方法,可以实现在旧的手机上实现动画效果.采用了类似于豌豆荚的开眼项目使用的技术.github上可能有在5.0以下的兼容包,但是个人并不推荐使用第三方的UI工具. Preview 实现原理 最近逛业界良心酷安网,发现了豌豆荚的一款叫做

教你实现类似于格瓦拉启动页中的放大转场动画(OC&amp;Swift)

教你实现类似于格瓦拉启动页中的放大转场动画(OC&Swift) 一.前言 用过格瓦拉电影,或者其他app可能都知道,一种点击按钮用放大效果实现转场的动画现在很流行,效果大致如下 在iOS中,在同一个导航控制器你可以自定义转场动画实现两个viewController之间的过渡.实际上在iOS7之后,通过实现UIViewControllerAnimatedTransitioning或者UIViewControllerContextTransitioning协议,就可以简单的自定义转场动画,比如一个N