Search code examples
iosiphoneuiimagecore-graphics

how to flip array of images in viewDidLoad?


i am learning core animation in iOS first thing i have to know how to flip array of images in view

here my sample codes:

NSArray *animationArray=[NSArray arrayWithObjects:
                         [UIImage imageNamed:@"homebg.png"],
                         [UIImage imageNamed:@"splash.jpg"],
                         [UIImage imageNamed:@"index3.png"],
                         [UIImage imageNamed:@"image2.png"],
                         [UIImage imageNamed:@"image4.png"],
                         [UIImage imageNamed:@"index6.png"],
                         nil];

imageView.backgroundColor=[UIColor purpleColor];
imageView.animationImages=animationArray;
imageView.transform = CGAffineTransformMakeScale(-1, 1);
imageView.animationDuration=3.9;
imageView.animationRepeatCount=0;
[imageView startAnimating];

it worked but i am not satisfied i want images to be animated and attract the end user


Solution

  • // in view Load
    _slide = 0
    [self changeSlide];
    
    // Loop gallery 
    NSTimer *timer = [NSTimer timerWithTimeInterval:5.0f target:self selector:@selector(changeSlide) userInfo:nil repeats:YES];
    [[NSRunLoop mainRunLoop] addTimer:timer forMode:NSRunLoopCommonModes];
    
    
    - (void)changeSlide
    {
    
    if(_slide > _galleryImages.count-1) _slide = 0;
    
    UIImage *toImage = [UIImage imageNamed:_galleryImages[_slide]];
    [UIView transitionWithView:_yourimageView
                      duration:0.6f
                       options:UIViewAnimationOptionTransitionFlipFromLeft
                    animations:^{
                        _yourimageView.image = toImage;
    
                    } completion:nil];
    _slide++;
    //    }
    }
    

    Create a Timer and Array Of images .Animate ur images with various FlipAnimation option,Hope this helps you

    enter image description here