UIImageView 平滑过渡图片切换

eg:

#import "ViewController.h"


@interface ViewController ()

@property (nonatomic, strong) UIImageView *imageView;

@property (nonatomic, copy) NSArray *images;

@end


@implementation ViewController


- (void)viewDidLoad

{

    [super viewDidLoad];


    self.images = @[[UIImage imageNamed:@"1.png"],

                    [UIImage imageNamed:@"2.png"]

                    ];

    

    self.imageView = [[UIImageView alloc] initWithFrame:CGRectMake(100, 100, 100, 100)];

    [self.imageView setBackgroundColor:[UIColor redColor]];

    [self.view addSubview:self.imageView];

}


- (void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event

{

    //set up crossfade transition

    CATransition *transition = [CATransition animation];

    transition.type = kCATransitionFade;

    transition.duration = 2.0;

    [self.imageView.layer addAnimation:transition forKey:nil];

    

    //cycle to next image

    UIImage *currentImage = self.imageView.image;

    NSUInteger index = [self.images indexOfObject:currentImage];

    index = (index + 1) % [self.images count];

    self.imageView.image = self.images[index];

}


@end


没有更多推荐了,返回首页

私密
私密原因:
请选择设置私密原因
  • 广告
  • 抄袭
  • 版权
  • 政治
  • 色情
  • 无意义
  • 其他
其他原因:
120
出错啦
系统繁忙,请稍后再试