我试图让三个图像一次淡入和淡出一个。我想我很接近这段代码,但它并没有像我预期的那样工作。
我希望的是,每张图像都会在 0.5 秒内淡出,然后在屏幕上停留 2 秒,然后在 0.5 秒内淡出。一旦第三张图像消失,我希望它停止。
下面的代码一遍又一遍地淡出第一张图像,我似乎无法正确降低时间。任何帮助都会很棒!
-(void) viewDidLoad {
pImageC = [[UIImageView alloc]init];
NSArray *animationArray = [NSArray arrayWithObjects:[UIImage
imageNamed:@"p_image_a.png"],[UIImage imageNamed:@"p_image_b.png"],[UIImage
imageNamed:@"p_image_c.png"], nil]; //add your images here
[NSTimer scheduledTimerWithTimeInterval:0.5 target:self selector:@selector(crossfade)
userInfo:nil repeats:YES];
[pImageC setFrame:CGRectMake(0,0,320,367)];
pImageC.animationImages = animationArray; //mainImageView is imageview
pImageC.animationDuration = 2;
pImageC.animationRepeatCount = 0;
[pImageC startAnimating];
[self.view addSubview:pImageC];
}
- (void)crossfade {
[UIView animateWithDuration:0.5 delay:0.0 options:UIViewAnimationOptionCurveEaseInOut
animations:^{
pImageC.alpha = !pImageC.alpha;
}completion:^(BOOL done){
//
}];
}