如何在viewDidLoad中翻转图像数组?

时间:2015-09-16 11:46:15

标签: ios iphone uiimage core-graphics

我正在学习iOS中的核心动画首先我必须知道如何在视图中翻转图像

这里是我的示例代码:

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];

它有效,但我不满意我希望图像动画并吸引最终用户

1 个答案:

答案 0 :(得分:0)

// 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++;
//    }
}

创建一个计时器和图像数组。使用各种Flip动画选项动画你的图像,希望这可以帮助你

enter image description here