zoukankan      html  css  js  c++  java
  • 转场动画(长按屏幕有不同的翻转效果)

    //

    //  ViewController.m

    //  UI-NO-39-2 转场动画 1

    //

    //  Created by 容伟 on 15/9/30.

    //  Copyright (c) 2015年 容伟. All rights reserved.

    //

     

    /*

     CATransition 转场动画  可以切换视图、视图控制器

     type 转场动画的 动画效果

     subtype 转场动画  动画的方向

     

     kCATransitionFade   交叉淡化过渡

     kCATransitionMoveIn 新视图移到旧视图上面

     kCATransitionPush   新视图把旧视图推出去

     kCATransitionReveal 将旧视图移开,显示下面的新视图

     

     

     私有api 不建议使用 苹果不提供维护 并且有可能app审核不通过

     pageCurl            向上翻一页

     pageUnCurl          向下翻一页

     rippleEffect        滴水效果

     suckEffect          收缩效果 如一块布被抽走

     cube                立方体效果

     oglFlip             上下翻转效果

     */

    /* 过渡效果

     fade     //交叉淡化过渡(不支持过渡方向) kCATransitionFade

     push     //新视图把旧视图推出去  kCATransitionPush

     moveIn   //新视图移到旧视图上面   kCATransitionMoveIn

     reveal   //将旧视图移开,显示下面的新视图  kCATransitionReveal

     cube     //立方体翻滚效果

     oglFlip  //上下左右翻转效果

     suckEffect   //收缩效果,如一块布被抽走(不支持过渡方向)

     rippleEffect //滴水效果(不支持过渡方向)

     pageCurl     //向上翻页效果

     pageUnCurl   //向下翻页效果

     cameraIrisHollowOpen  //相机镜头打开效果(不支持过渡方向)

     cameraIrisHollowClose //相机镜头关上效果(不支持过渡方向)

     */

     

    /* 过渡方向

     kCATransitionFromRight

     kCATransitionFromLeft

     kCATransitionFromBottom

     */

    #import "ViewController.h"

    #import "NextViewController.h"

     

    // 枚举类型

    typedef enum Direction {

        Right = 0,

        Left,

    }Direction;

     

    @interface ViewController ()

    {

        NSArray *imageList;

        UIImageView *showImage;

        int index;

    }

    @end

     

    @implementation ViewController

     

    - (void)viewDidLoad {

        [super viewDidLoad];

        imageList = @[@"9.jpg", @"11.jpg", @"12.jpg", @"13.jpg"];

        showImage = [[UIImageView alloc] initWithFrame:self.view.frame];

        showImage.image = [UIImage imageNamed:imageList[0]];

        showImage.userInteractionEnabled = YES;

        [self.view addSubview:showImage];

        

        UISwipeGestureRecognizer *rightSwipeGesture = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(right:)];

        rightSwipeGesture.direction = UISwipeGestureRecognizerDirectionRight;

        [self.view addGestureRecognizer:rightSwipeGesture];

        

        UISwipeGestureRecognizer *leftSwipeGesture = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(left:)];

        leftSwipeGesture.direction = UISwipeGestureRecognizerDirectionLeft;

        [self.view addGestureRecognizer:leftSwipeGesture];

     

        

    //    添加长按手势

        UILongPressGestureRecognizer *next = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(next:)];

        [self.view addGestureRecognizer:next];

    }

     

    #pragma mark - 切换试图控制器

    - (void)next:(UILongPressGestureRecognizer *)sender {

        if (sender.state == UIGestureRecognizerStateBegan) {

            NextViewController *next = [[NextViewController alloc] init];

        

            

            CATransition *animation = [CATransition animation];

            animation.type = @"cube";

            animation.subtype = kCATransitionFromLeft;

            animation.duration = 1;

            [self.navigationController.view.layer addAnimation:animation forKey:nil];

            

    //        如果使用 自定义的转场动画  必须禁用系统的动画

        [self.navigationController pushViewController:next animated:NO];

            }

    }

     

    - (void)right:(UILongPressGestureRecognizer *)sender {

        [self changeImageWithDirection:Right];

    }

    - (void)left:(UILongPressGestureRecognizer *)sender {

        [self changeImageWithDirection:Left];

    }

     

    - (void)changeImageWithDirection:(Direction)direction {

    //    通过判断 图片是自加 或者 自减

        index = direction == Right ? [self addSelf]:[self releaseSelf];

     

    #pragma mark - 添加转场动画

        CATransition *transition = [CATransition animation];

        transition.type = direction == Right ? @"cube":@"rippleEffect";

        transition.subtype = direction == Right ? kCATransitionFromRight:kCATransitionFromLeft;

        transition.duration = 1;

        [showImage.layer addAnimation:transition forKey:nil];

        

        showImage.image = [UIImage imageNamed:imageList[index]];

    }

     

    #pragma mark - 向左滑动 图片自加

    // 需要通过方向  判断 自加 还是 自减  把计算好的值 赋给全局变量index

    - (int)addSelf {

        index ++;

    //    如果超出了 图片的元素  修复成0

    //    如果没有超出  返回 自加之后的值

        return index >= imageList.count-1 ? 0:index;

    }

     

    #pragma mark - 向右滑动 图片自减

    - (int)releaseSelf {

        index --;

        return index < 0 ? (int)imageList.count-1:index;

    }

     

     

     

        

    - (void)didReceiveMemoryWarning {

        [super didReceiveMemoryWarning];

        // Dispose of any resources that can be recreated.

    }

     

    @end

     

  • 相关阅读:
    1033 To Fill or Not to Fill (25分)(贪心)
    CentOS(五)--Linux系统的分区概念
    Linux安装Oracle 11G过程(测试未写完)
    【VMware虚拟化解决方案】设计和配置VMware vCenter 5.5
    CentOS(四)--Linux系统的启动级别
    CentOS(三)--初识linux的文件系统以及用户组等概念
    CentOS(二)--初识linux的一些常用命令
    CentOS(一)--CentOS6.4环境搭建
    Linux c/c++图片传输功能(中级版)
    remote uptime 服务器程序
  • 原文地址:https://www.cnblogs.com/wukun16/p/4884172.html
Copyright © 2011-2022 走看看