Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Animated Gif inside UITextView

I had a look at this question and it didn't work. I am also trying to avoid this sort of solution. In the end I am willing to go with a CADisplayLink and change each frame manually. Still, is there a simpler way to do this?

like image 249
Rui Peres Avatar asked Mar 19 '15 00:03

Rui Peres


2 Answers

An animated gif if just a collection of images which are displayed in sequence at a timed interval. You can do this with a UIImageView like this:

imageView.animationImages = [UIImage(named: "uploadFrame0")!, UIImage(named: "uploadFrame1")!, UIImage(named: "uploadFrame2")!, UIImage(named: "uploadFrame3")!, UIImage(named: "uploadFrame4")!, UIImage(named: "uploadFrame5")!, UIImage(named: "uploadFrame6")!, UIImage(named: "uploadFrame7")!, UIImage(named: "uploadFrame8")!]
imageView.animationDuration = 1
imageView.startAnimating()

Then you can use exclusion paths to make the text flow around it.

like image 130
Bjørn Ruthberg Avatar answered Sep 27 '22 21:09

Bjørn Ruthberg


Use exclusion paths to define areas that are kept free, than add the image with an image view.

NSMutableArray *exclutionPaths = [NSMutableArray array];
[exclutionPaths addObject:[UIBezierPath bezierPathWithRect:CGRectInset(imageFrame, -4, 0)]];
[_textView.textContainer setExclusionPaths:exclutionPaths];
[_textView addSubview:imageView];
like image 25
vikingosegundo Avatar answered Sep 27 '22 21:09

vikingosegundo