문제

I'm trying to do a crossfade between two images, but when you call the function to exchange pictures, everything is white and appears soon after the second image and the transition does not occur. What am I doing wrong?

thanks

My code:

#import <QuartzCore/QuartzCore.h>

#define QT_IMG_HOME 2

@interface UFHomeViewController () {
  int idxImgBG;
}

@end


- (void)viewDidLoad
{
    [super viewDidLoad];
// Do any additional setup after loading the view.
    idxImgBG = 1;
    [self performSelector:@selector(changeBGImage) withObject:nil afterDelay:3.0];
}

-(void)changeBGImage {
    if(idxImgBG < QT_IMG_HOME)
        idxImgBG = idxImgBG + 1;
    else
        idxImgBG = 1;

    UIImage *image1 = _imgBG.image;
    UIImage *image2 = [UIImage imageNamed:[NSString stringWithFormat:@"home%d.jpg", idxImgBG]];

    CABasicAnimation *crossFade = [CABasicAnimation animationWithKeyPath:@"contents"];
    crossFade.duration = 1;
    crossFade.fromValue = (__bridge id)(image1.CGImage);
    crossFade.toValue = (__bridge id)(image2.CGImage);
    [_imgBG.layer addAnimation:crossFade forKey:@"animateContents"];

    _imgBG.image = image2;

    [self performSelector:@selector(changeBGImage) withObject:nil afterDelay:4];
}
도움이 되었습니까?

해결책

This solved. Problems with my device.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top