UIImageView *splash = [[UIImageView alloc] initWithFrame:self.window.bounds];
        UIImageView *splash2 = [[UIImageView alloc] initWithFrame:self.window.bounds];
        splash.image = [UIImage imageNamed:@"img1"];
        splash2.image = [UIImage imageNamed:@"img2"];
        [self.window addSubview:splash];
        
        [UIView animateWithDuration:4.0 animations:^{
            splash.alpha = 0.0;
        } completion:^(BOOL finished){
            [splash removeFromSuperview];
            
        }];
        
        [self.window addSubview:splash2];
        [UIView animateWithDuration:4.0 animations:^{
            splash2.alpha = 0.0;
        } completion:^(BOOL finished){
            [splash2 removeFromSuperview];
        }];我想要的结果是第一个图片直接显示,然后淡出,然后淡入第二个图片,然后淡出
如上,这样是错误的,是第一个图片直接切换到第二个图片,然后交叉在一起淡出,不知道怎么改?谢谢各位dx~

解决方案 »

  1.   

    [self.window addSubview:splash2];
            [UIView animateWithDuration:4.0 animations:^{
                splash2.alpha = 0.0;
            } completion:^(BOOL finished){
                [splash2 removeFromSuperview];
            }];修改为 8秒 不就好了吗
      

  2.   

            [UIView animateWithDuration:4.0 animations:^{
                splash.alpha = 0.0;
            } completion:^(BOOL finished){
                [splash removeFromSuperview];
                
                [self.window addSubview:splash2];
                [UIView animateWithDuration:4.0 animations:^{
                    splash2.alpha = 0.0;
                } completion:^(BOOL finished){
                    [splash2 removeFromSuperview];
                }];
            }];
            
           
      

  3.   

    UIImageView *splash = [[UIImageView alloc] initWithFrame:self.window.bounds];
        UIImageView *splash2 = [[UIImageView alloc] initWithFrame:self.window.bounds];
        splash.image = [UIImage imageNamed:@"img1"];
        splash2.image = [UIImage imageNamed:@"img2"];
        [self.window addSubview:splash];
        
        [UIView animateWithDuration:4.0 animations:^{
            splash.alpha = 0.0;
        } completion:^(BOOL finished){
            [splash removeFromSuperview];
            //搬个家就好了
            [self.window addSubview:splash2];
            [UIView animateWithDuration:4.0 animations:^{
                splash2.alpha = 0.0;
            } completion:^(BOOL finished){
                [splash2 removeFromSuperview];
            }];        
            
        }];居然还有这种问题,这是不使用延迟的做法,不想这样嵌套就dispatch_after 
      

  4.   

    dispatch_after写法[UIView animateWithDuration:4.0 animations:^{
            splash.alpha = 0.0;
        } completion:^(BOOL finished){
            [splash removeFromSuperview];
            
                    
            
            
        }];
        
        double delayInSeconds = 4.0;
        dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC));
        dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
            [self.window addSubview:splash2];
            [UIView animateWithDuration:4.0 animations:^{
                splash2.alpha = 0.0;
            } completion:^(BOOL finished){
                [splash2 removeFromSuperview];
            }];    });