On OS X, the standard QuickTime Player application can record (a part of) your screen, or record the screen of an iOS device over the lightning cable.
You then get a .mov file. You can convert this into an animated gif of slightly smaller size with ffmpeg. You'll need to install homebrew first, and using the brew command, install ffmpeg as follows:
$ brew install ffmpeg
Then open a terminal and change to the desktop folder or wherever you saved the movie file, and issue the following command:
$ ffmpeg -i demo.mov -r 15 demo.gif
Drag the resulting demo.gif to Safari to view it. The quality is pretty bad, but hey, animated gifs are all the rage nowadays.
Edit 2020-08-27: it's possible to improve the resulting output with an additional option. Example:
$ ffmpeg -i demo.mov -filter_complex "[0]split[vid][pal];[pal]palettegen[pal];[vid][pal]paletteuse" demo.gif