UIImage翻转图像方向

时间:2014-02-12 14:21:01

标签: ios animation uiimageview uiimage

对于某个UIImageView animationImages,我希望创建2个数组 - 每个方向一个。 我有png文件我可以加载到其中一个方向,我希望翻转每个图像并将其添加到第二个方向阵列。

我试着这样做:

    _movingLeftImages = [NSMutableArray array];
    _movingRightImages = [NSMutableArray array];
    int imagesCounter = 0;
    while (imagesCounter <= 8)
    {
        NSString* imageName = [NSString stringWithFormat:@"movingImg-%i", imagesCounter];

        UIImage* moveLeftImage = [UIImage imageNamed:imageName];
        [_movingLeftImages addObject:moveLeftImage];

        UIImage* moveRightImage = [UIImage imageWithCGImage:moveLeftImage.CGImage scale:moveLeftImage.scale orientation:UIImageOrientationUpMirrored];
        [_movingRightImages addObject:moveRightImage];

        imagesCounter++;
    }

在相关事件中,我使用相关数组加载UIImageView animationImages;像这样:

if ( /*should move LEFT event*/ )
    {
        movingImageView.animationImages = [NSArray arrayWithArray:_movingLeftImages];
    }
    if ( /*should move RIGHT event*/ )
    {
        movingImageView.animationImages = [NSArray arrayWithArray:_movingRightImages];
    }

图像未翻转。他们仍然在那里。

知道怎么处理这个吗?

1 个答案:

答案 0 :(得分:0)

使用此代码制作动画图像

UIImageView * animatedImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 200,200)];

  NSArray *imageNames = @[@"bird1.png", @"bird2.png"];
  animTime =.0;
 [animatedImageView setAnimationImages:imageNames] ;
 animatedImageView.animationDuration =  animTime;
 animatedImageView.animationRepeatCount = 1;
[self.view addSubview: animatedImageView];
[animatedImageView startAnimating];