self.imageView = [[UIImageView alloc] initWithFrame:(CGRectMake(0, 0, 100, 100))];
self.imageView.image = [UIImage imageNamed:@"circle"];
[self.view addSubview:self.imageView];
[self startAnimation];- (void)startAnimation
{
// UIViewAnimationOptionCurveLinear匀速执行(默认就是它)
[UIView animateWithDuration:0.01 delay:0 options:UIViewAnimationOptionCurveLinear animations:^{
self.imageView.transform = CGAffineTransformMakeRotation(i * M_PI / 180.f);
} completion:^(BOOL finished) {
i += 7; [self startAnimation];
}];
}
把GIF图片里的每一帧复制出来,mac上直接全选,拖出来就行。拖出来是TIFF格式,没关系,一样用。
self.imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
NSMutableArray *image_arr = [NSMutableArray array];
for (int i = 1; i < 50; i++) {
NSString *name = [NSString stringWithFormat:@"textGIF%d.tiff", i];
UIImage *image = [[UIImage alloc] init];
image = [UIImage imageNamed:name];
[image_arr addObject:image];
NSLog(@"image:%@", image);
}
NSLog(@"%@", self.imageView);
self.imageView.animationImages = image_arr;
self.imageView.animationDuration = 4;
self.imageView.animationRepeatCount = 100;
[self.imageView startAnimating];
[self.view addSubview:self.imageView];
本文介绍如何使用Objective-C在iOS应用中实现图片旋转动画及GIF动画效果。通过UIImageView展示单张图片并设置动画属性,利用UIView动画方法实现平滑旋转效果;通过加载一系列图片到NSMutableArray中,设置UIImageView的animationImages属性播放GIF动画。
2673

被折叠的 条评论
为什么被折叠?



