Milk for Coffee - Shake and Hit
I'm a bit of a coffee nut, having bought my own espresso machine &amp; grinder and have been pulling my own shots and learning how to create different coffee drinks for some years now. I am by no means an expert, however: 

What you're seeing when the barista is swirling/tapping the milk jug is called "polishing". It's the step after they've steamed it and does two things

1) The swirling "polishes" the milk/foam to give it a nice "shine" (best described as looking like paint).

2) The tapping removes any larger bubbles - your aim for steamed milk for coffee drinks is generally to get a "micro foam" which as it sounds, has micro bubbles.

Bit of extra info:

To control how much foam you get is right at the start, when you initially start the steaming - you have the steam wand just under the surface of the milk so it introduces as much air as you need. Similar idea to whipping cream really. After introducing the air, you submerge the steam wand and use the steam to "spin" the milk - this mixes the foam with the milk to increase it's volume (and also starts the "polishing" process).

To control where the foam goes, you adjust how quickly you pour. Just dumping it all in the cup will churn the milk and foam together. Pouring with a spout in a more controlled fashion will pour the milk in first, then the foam after (same idea as helium balloons rising, the foam is lighter than the milk)

Hope this helps :)