【问题标题】:how to flip array of images in viewDidLoad?如何在 viewDidLoad 中翻转图像数组?
【发布时间】:2015-09-16 11:46:14
【问题描述】:

我正在学习 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];

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

【问题讨论】:

  • 为什么不将翻转的图像保存在另一个数组中并一个接一个地做动画?

标签: ios iphone uiimage core-graphics


【解决方案1】:
// 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++;
//    }
}

创建一个计时器和图像数组。使用各种FlipAnimation 选项为您的图像设置动画,希望这对您有所帮助

【讨论】:

  • 谢谢你的回答我可以知道什么是_slide我的意思是它的声明吗?
  • 它的整数默认值为0._galleryImages[_slide] 有助于访问具有索引和递增的图像
  • 使用任一动画UIViewAnimationOptionTransitionFlipFromLeft|UIViewAnimationOptionTransitionFlipFromRight |UIViewAnimationOptionTransitionFlipFromTop |UIViewAnimationOptionTransitionFlipFromBottom
  • 我还附上了演示它是如何为我工作的。检查编辑。
猜你喜欢
  • 2011-03-01
  • 1970-01-01
  • 1970-01-01
  • 2019-04-03
  • 2022-11-30
  • 1970-01-01
  • 2013-06-01
  • 2022-01-22
  • 2021-09-06
相关资源
最近更新 更多