ios - UIImageView通过startAnimating方法,播放经过CGImage翻转后的图像无效
ringa_lee
ringa_lee 2017-04-17 13:09:28
[iOS讨论组]

UIImageView通过startAnimating方法,播放经过CGImage翻转后的图像时,该图像全是原始图像,即旋转生成的UIImage的array在startAnimating无效。该怎么解决?

大家可以测试以下代码:

//TEST 
UIImageView* imageView = [[UIImageView alloc] initWithFrame:CGRectMake(30.0, 30.0, 50.0, 50.0)]; 
UIImage* image = [UIImage imageNamed:@"Image.png"]; 
UIImage* orientImage = [UIImage imageWithCGImage:image.CGImage scale:1.0 orientation:UIImageOrientationDownMirrored]; 

imageView.animationImages = [[NSArray alloc] initWithObjects:orientImage, orientImage, nil]; 
imageView.animationDuration = 0.3; 
imageView.animationRepeatCount = 10; 
[imageView startAnimating];

[self.view addSubview:imageView];

PS:这里的翻转不是旋转,是OrientationUpMirrored,就是水平翻转、左右方向换过来;这里说的动画,就是像UIImageView的startAnimating的精灵动画,不是UIView animation那种关键帧动画。

ringa_lee
ringa_lee

ringa_lee

全部回复(1)
大家讲道理

首先,

imageView.animationImages = [[NSArray alloc] initWithObjects:orientImage, orientImage, nil];

你不觉得两个对象是一样的?

其次,
你这个

 [UIImage imageWithCGImage:image.CGImage scale:1.0 orientation:UIImageOrientationDownMirrored];

创建出来的UIImage是不是和原图一样呢?

翻转的动画为什么不用CoreAnimation来实现呢?不需要用UIImageView的startAnimating

CALayer *layer = [CALayer layer]
// ... set bounds, position, etc.
layer.contents = [UIImage imageNamed:@"image"].CGImage;

[self.view.layer addSubLayer:layer];

CAKeyFrameAnimation *transformAnim = [CAKeyFrameAnimation animWithKeyPath:@"transform.rotation.x"];
// ... set duration, beginTime, etc.
transformAnim.keyTimes = @[@(0.0), @(1.0)];
transformAnim.values = @[(0.0), @(M_PI / 2)];
[layer addAnimation:transformAnim forKey:@"transform.rotation.x"];
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号