码迷,mamicode.com
首页 > 其他好文 > 详细

图片切换的效果

时间:2015-12-27 20:26:36      阅读:145      评论:0      收藏:0      [点我收藏+]

标签:

图片切换的效果

技术分享

 

效果

技术分享技术分享

 

源码

https://github.com/YouXianMing/Animations

//
//  LiveImageView.h
//  Animations
//
//  Created by YouXianMing on 15/12/27.
//  Copyright © 2015年 YouXianMing. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface LiveImageView : UIImageView

@property (nonatomic)  CGFloat  duration;

@end
//
//  LiveImageView.m
//  Animations
//
//  Created by YouXianMing on 15/12/27.
//  Copyright © 2015年 YouXianMing. All rights reserved.
//

#import "LiveImageView.h"

@interface LiveImageView () {

    CALayer  *_Layer;
}

@end

@implementation LiveImageView

- (id)initWithFrame:(CGRect)frame {
    
    if ([super initWithFrame:frame]) {
        
        _duration = 0.3f;
        _Layer    = self.layer;
    }
    
    return self;
}

@synthesize image = _image;

- (void)setImage:(UIImage *)image {
    
    if (_image != image) {
        
        CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"contents"];
        animation.fromValue         = (__bridge id)(_image.CGImage);
        animation.toValue           =  (__bridge id)(image.CGImage);
        animation.duration          = _duration;
        _Layer.contents             = (__bridge id)(image.CGImage);
        [_Layer addAnimation:animation forKey:nil];
        
        _image = image;
    }
}

- (UIImage *)image {
    
    return _image;
}

@end

 

细节

技术分享

 

图片切换的效果

标签:

原文地址:http://www.cnblogs.com/YouXianMing/p/5080655.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!