自动淡入和淡出多个图像

时间:2012-10-11 11:51:58

标签: ios uiimageview fade

我在这里需要帮助。 我使用故事板,并希望自动淡出淡出照片显示。 问题是,我有10个图像,现在不知道如何编程。 我希望有人可以帮助我。

1 个答案:

答案 0 :(得分:3)

  mainImageView = [[UIImageView alloc]init];
    NSArray *animationArray = [NSArray arrayWithObjects:[UIImage imageNamed:@"first.png"],[UIImage imageNamed:@"second.png"],[UIImage imageNamed:@"third.png"],[UIImage imageNamed:@"fourth.png"],[UIImage imageNamed:@"fifth.png"],[UIImage imageNamed:@"sixth.png"],[UIImage imageNamed:@"seventh.png"],[UIImage imageNamed:@"eight.png"],[UIImage imageNamed:@"nine.png"],[UIImage imageNamed:@"ten.png"], nil]; //add your images here
                               [NSTimer scheduledTimerWithTimeInterval:0.5 target:self selector:@selector(crossfade) userInfo:nil repeats:YES];
    [mainImageView  setFrame:CGRectMake(50,50,100,100)];
                               mainImageView.animationImages = animationArray; //mainImageView is   imageview
                               mainImageView.animationDuration = 10;
                               mainImageView.animationRepeatCount = 0;
                               [mainImageView startAnimating];


     [self.view addSubview:mainImageView];


    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
}

- (void)crossfade {
    [UIView animateWithDuration:0.5 delay:0.0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
                                       mainImageView.alpha = !mainImageView.alpha;
                                   }completion:^(BOOL done){
                                    //
                }];
}