【问题标题】:UIImage Flip Image DirectionUIImage 翻转图像方向
【发布时间】:2014-02-12 14:21:01
【问题描述】:

对于某个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 动画图像;像这样:

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

图像不翻转。它们保持原样。

知道如何处理吗?

【问题讨论】:

  • 您确定您使用的方向正确吗?也许你可以上传一张你想要达到的目标的图片。
  • 使用 QuartzCore 提供给您的视图的 .layer 属性的 .transformation 属性来简单地翻转 uiimageview 而不是图像
  • @A'saDickens,我应该如何翻转?我对这个功能不熟悉......我应该使用它的哪个功能来实现这个镜像?
  • @GadMarkovits,我使用了错误的方向...我编辑了它。尽管如此,图像仍无法正确加载到镜像的 UIImage - 它们与原始图像保持相同......
  • 如果你想以编程方式翻转图像,你需要使用 ImageContext 功能,如果你想翻转 uiimageview 以便你没有图像的多个引用,那么你需要使用苹果提供的框架 框架:3 我将评论链接以显示 2 个示例,您可以选择看起来更容易的那些

标签: ios animation uiimageview uiimage


【解决方案1】:

使用此代码为图像设置动画

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

【讨论】:

    猜你喜欢
    • 2012-03-28
    • 1970-01-01
    • 1970-01-01
    • 2011-07-28
    • 2017-08-30
    • 2020-02-07
    • 1970-01-01
    • 2018-07-05
    • 2023-04-03
    相关资源
    最近更新 更多