0

我试图让三个图像一次淡入和淡出一个。我想我很接近这段代码,但它并没有像我预期的那样工作。

我希望的是,每张图像都会在 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){
        //
    }];
}
4

1 回答 1

0

尝试这样的交叉淡入淡出动画

- (void)crossfade 
{
    [UIView animateWithDuration:0.3 delay:0.0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
        self.animationImageView.alpha = 0.0;
    }completion:^(BOOL done){
        [self performAnimationOnView];

        [UIView animateWithDuration:0.3 delay:0.0 options:UIViewAnimationOptionCurveEaseIn animations:^{
            self.animationImageView.alpha = 1.0;
        }completion:^(BOOL done){


        }];


    }];

}
于 2013-06-25T12:34:10.767 回答