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?
Bjørn Ruthberg
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.
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];
来源:https://stackoverflow.com/questions/29135232/animated-gif-inside-uitextview