1
두 이미지간에 크로스 페이드를 시도하고 있지만 사진을 교환하기 위해 함수를 호출하면 모든 것이 흰색으로 표시되고 두 번째 이미지가 나타나고 전환이 발생하지 않는 즉시 나타납니다. 내가 도대체 뭘 잘못하고있는 겁니까?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