How to crossfade between 2 images on iPhone using Core Animation

后端 未结 6 509
既然无缘
既然无缘 2020-11-30 18:38

I\'m doing this to learn how to work with Core Animation animatable properties on iPhone (not to learn how to crossfade images, per se).

Reading similar questions on

6条回答
  •  我在风中等你
    2020-11-30 19:15

    - (void)viewDidLoad
    {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    self.navigationController.navigationBarHidden=false;
    UIImage *img=[UIImage imageNamed:@"images.jpeg"];
    imgview=[[UIImageView alloc]init];
    imgview.frame=CGRectMake(30,90, img.size.width, img.size.height);
    [self.view addSubview:imgview];
    [self animateImages];
    }
    - (void)animateImages
    {
    static int count = 0;
    NSArray *animationImages = @[[UIImage imageNamed:@"images.jpeg"], [UIImage imageNamed:@"images (1).jpeg"]];
    UIImage *image = [animationImages objectAtIndex:(count % [animationImages count])];
    
    [UIView transitionWithView:imgview
                      duration:2.0f // animation duration
                       options:UIViewAnimationOptionTransitionCrossDissolve
                    animations:^{
                        imgview.image = image;
                    } completion:^(BOOL finished) {
                        [self animateImages];
                        count++;
                    }];
    

    }

提交回复
热议问题