How would i make a weapon sway affect when i move camera?

For example in cod when you move the camera fast the weapon would move in the opposite direction. Any help would be great.