【发布时间】: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