Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/101.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 淡入淡出图像时的计时困难_Iphone_Ios_Objective C - Fatal编程技术网

Iphone 淡入淡出图像时的计时困难

Iphone 淡入淡出图像时的计时困难,iphone,ios,objective-c,Iphone,Ios,Objective C,我试图有三个图像淡入淡出一次一个。我想我已经非常熟悉这段代码了,但它并没有像我预期的那样工作 我所希望的是,每个图像将在0.5秒内淡入,然后在屏幕上保持2秒,然后在0.5秒内淡出。一旦第三个图像消失,我希望它停止 下面的代码一次又一次地淡出第一幅图像,我似乎无法正确地确定时间。任何帮助都会很好 -(void) viewDidLoad { pImageC = [[UIImageView alloc]init]; NSArray *animationArray = [NSArray

我试图有三个图像淡入淡出一次一个。我想我已经非常熟悉这段代码了,但它并没有像我预期的那样工作

我所希望的是,每个图像将在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){
        //
    }];
}

对于交叉淡入淡出动画,请尝试类似的方法

- (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){


        }];


    }];

}

你的pImageC.alpha=!pImageC.alpha;毫无意义。alpha是一个浮点值,而不是布尔值。