首页 > 其他 > 详细

CATransition的简单使用

时间:2014-10-21 11:52:01      阅读:245      评论:0      收藏:0      [点我收藏+]

//
//  MJViewController.m
//  08-核心动画04-CATransition
//
//  Created by apple on 14-4-21.
//  Copyright (c) 2014年 itcast. All rights reserved.
//

#import "MJViewController.h"

@interface MJViewController ()

// 上一张
- (IBAction)previous;

// 下一张
- (IBAction)next;
@property (weak, nonatomic) IBOutlet UIImageView *iconView;

/**
 *  当前图片的索引
 */
@property (nonatomic, assign) int index;
@end

@implementation MJViewController

- (IBAction)previous {
    self.index--;
    if (self.index == -1) {
        self.index = 8;
    }
    
    NSString *filename = [NSString stringWithFormat:@"%d.jpg", self.index + 1];
    self.iconView.image = [UIImage imageNamed:filename];
    
    CATransition *anim = [CATransition animation];
//    anim.type = @"cube";
//    anim.subtype = kCATransitionFromLeft;
    anim.type = @"pageUnCurl";
    anim.duration = 0.5;
    [self.view.layer addAnimation:anim forKey:nil];
}

- (IBAction)next {
    self.index++;
    if (self.index == 9) {
        self.index = 0;
    }

    NSString *filename = [NSString stringWithFormat:@"%d.jpg", self.index + 1];
    self.iconView.image = [UIImage imageNamed:filename];
    
    // 转场动画
    CATransition *anim = [CATransition animation];
    anim.type = @"pageCurl";
//    anim.type = kCATransition
//    anim.subtype = kCATransitionFromRight;
    anim.duration = 0.5;
    
    // 动画起点
//    anim.startProgress = 0.0;
//
    //动画终点
//    anim.endProgress = 0.5;
    
    [self.view.layer addAnimation:anim forKey:nil];
}
@end

CATransition的简单使用

原文:http://www.cnblogs.com/xiaokanfengyu/p/4039617.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!