ios - UIImageView 开始动画不会对翻转图像进行动画处理

标签 ios objective-c cocoa-touch animation uiimageview

我有一组面向一侧的图像(男人面向右侧),我使用此方法翻转它,然后将其添加到 uiimageview 的animationImages 中。然而,添加翻转图像后,然后开始动画,动画仍然面向右侧。

manRunAnimations = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 64, 64)];
NSArray *manAniRunArray = @[[UIImage imageNamed:@"robot1"],
                            [UIImage imageNamed:@"robot2"],
                            [UIImage imageNamed:@"robot3"],
                            [UIImage imageNamed:@"robot4"],
                            [UIImage imageNamed:@"robot5"],
                            [UIImage imageNamed:@"robot6"],
                            ];


manRunAnimationsf = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 64, 64)];

NSMutableArray *flippedRunAnimationImages = [[NSMutableArray alloc] init];

for( UIImage *image in manAniRunArray)
{
    UIImage * flippedImage = [UIImage imageWithCGImage:image.CGImage scale:image.scale orientation:UIImageOrientationRightMirrored];
    [flippedRunAnimationImages addObject:flippedImage];
}

manRunAnimationsf.animationImages = (NSArray *)flippedRunAnimationImages;

testImgView.image = [manRunAnimationsf.animationImages objectAtIndex:0];
manRunAnimationsf.animationDuration = runAnimationSpeedSlider.value;
[manRunAnimationsf startAnimating];

我什至使用它进行了测试

testImgView.image = [manRunAnimationsf.animationImages objectAtIndex:5];

这将在我执行操作之前在屏幕上正确显示翻转的图像之一

[manRunAnimationsf startAnimating];

一旦开始,动画就不会翻转!!

有人知道为什么吗?

最佳答案

我不敢相信没有人知道为什么,但我找到了解决方法。就是在startAnimating之前添加以下内容:

    manRunAnimationsf.transform = CGAffineTransformMake(-1,0,0,1,0,0);

我什至不需要在 for 循环中进行 CGImage 翻转。

但是手动图像翻转应该可以与 imageWithCGImage 方法一起使用,我真的很想知道为什么!你们让我很失望。 :p

关于ios - UIImageView 开始动画不会对翻转图像进行动画处理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15755142/

相关文章:

ios - 在 iOS 中访问 Magento Rest API - swift 3.0

ios - MailChimp中的电子邮件,名称和自定义属性(快速3)

ios - 检测时间是否以小时为单位的简单方法是什么?

ios - 静态单元格不显示在模拟器中

iphone - 如何使用 Assets Library 加速图像加载?

ios - 将动画应用于一系列 UILabel 属性文本

ios - 如何保持 uicollectionview 单元格之间的间距

iphone - 如何在 iPhone 中显示在应用程序启动时向下滚动的介绍屏幕?

objective-c - 为什么使用弱指针进行委托(delegate)?

objective-c - Obj C 委托(delegate)方法未分配给 UIButton (iOS)?