We study the general-setting quantum geometric phase acquired by a particle in a vibrating cavity. Solving the two-level theory with the rotating-wave approximation and the SU(2) method, we obtain analytic formulae that give excellent descriptions of the geometric phase, energy, and wavefunction of the resonating system. In particular, we observe a sudden π-jump in the geometric phase when the system is in resonance. We found similar behaviors in the geometric phase of a spin-1/2 particle in a rotating magnetic field, for which we developed a geometrical model to help visualize its evolution.