1
我試圖做兩個圖像之間的交叉淡入淡出,但是當您調用函數來交換圖片時,一切都是白色的,並在第二個圖像後不久出現,並且不會發生轉換。我究竟做錯了什麼?Crossfade圖像與CABasicAnimation不工作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];
}
這不是一個好的答案。請解釋您的設備出現了什麼問題,以及爲什麼它會停止您的動畫工作。 – TigerCoding