交叉淡入淡出图像与CABasic动画不起作用ios



我正在尝试在两个图像之间进行交叉淡入淡出,但是当您调用函数来交换图片时,所有内容都是白色的,并且在第二个图像之后不久出现,并且不会发生过渡。我做错了什么?

谢谢

我的代码:

#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];
}

这解决了。我的设备有问题。

相关内容

  • 没有找到相关文章

最新更新