首页 > 其他 > 详细

2016-1-10 核心动画学习 专场动画实例

时间:2016-01-11 20:05:57      阅读:177      评论:0      收藏:0      [点我收藏+]
//
//  ViewController.m
//  图片浏览器
//
//  Created by Mac on 16/1/11.
//  Copyright © 2016年 Mac. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()
- (IBAction)tap:(UITapGestureRecognizer *)tap;
@property (weak, nonatomic) IBOutlet UIImageView *imageView;
@property (nonatomic, strong) NSMutableArray *imgNames;
@property (nonatomic, assign) NSInteger currentImgIndex;

@end

@implementation ViewController
//- (NSInteger)currentImgIndex
//{
//    if (!_currentImgIndex) {
//        _currentImgIndex = 1;
//    }
//    return _currentImgIndex;
//}
- (NSMutableArray *)imgNames
{
    if (!_imgNames) {
        NSMutableArray *imgNames =[NSMutableArray array];
        for (NSInteger i = 1; i < 10; i ++) {
            NSString *img = [NSString stringWithFormat:@"%ld",i];
            [imgNames addObject:img];
        }
        _imgNames = imgNames;
    }
    return _imgNames;
}

- (void)viewDidLoad {
    [super viewDidLoad];
//    NSLog(@"%@",self.imgNames);
    // Do any additional setup after loading the view, typically from a nib.
//    self.imageView
    self.currentImgIndex = 1;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (IBAction)tap:(UITapGestureRecognizer *)tap{
    CGPoint location = [tap locationInView:tap.view];
    if (location.x <= self.view.bounds.size.width
        /2) {
//        NSLog(@"在左边");
        [self preImg];
    }else
    {
//        NSLog(@"在右边");
        [self nextImg];
    }
}
- (void)preImg
{
    if (self.currentImgIndex == 1) {
        
    }
    else{
        self.currentImgIndex -- ;
        NSString *preImgName = [NSString stringWithFormat:@"%ld",(self.currentImgIndex )];
        NSLog(@"%@",preImgName);
        self.imageView.image = [UIImage imageNamed:preImgName];
        CATransition *animation = [CATransition animation];
        animation.type = @"pageUnCurl";
        animation.subtype = @"fromRight";
        animation.duration = 0.45;
        [self.imageView.layer  addAnimation:animation forKey:nil];
    }
    
}
- (void)nextImg
{
    if (self.currentImgIndex == self.imgNames.count) {
        NSLog(@"最后");
    }else{
        self.currentImgIndex++;
        NSString  *nextImgName = [NSString stringWithFormat:@"%ld",self.currentImgIndex];
        NSLog(@"%@",nextImgName);

        self.imageView.image =[UIImage imageNamed:nextImgName];
        CATransition *animation = [CATransition animation];
        animation.type = @"pageCurl";
        animation.subtype = @"fromRight";
        animation.duration = 0.45;
        [self.imageView.layer  addAnimation:animation forKey:nil];
        
     }
}
@end

技术分享

2016-1-10 核心动画学习 专场动画实例

原文:http://www.cnblogs.com/BJTUzhengli/p/5122143.html

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