(a) The bandana on the end of his rifle flapped in the wind.
(b) Her hair blew up toward the sky with the wind.
The bandana and her hair moved in the wind or with the wind. ‘With’ seems to be “used to indicate the specific thing or person that is being referred to (-> refer to: "to have a direct connection or relationship to (something).” ‘In’ seems to be “used to indicate the conditions that are around someone or something.” [- All definitions are from Merriam-Webster's Learner's dictionary.]
(1) Is my supposition right?
(2) Are they used with distinctly different nuance or virtually interchangeable?