How do sunscreens protect the skin from UV rays?
Apart from titanium dioxide, the active species in sunscreens are organic compounds from different substance classes, such as cinnamates, benzophenones, benzimidazoles, and triazines.

The do absorb in the 280-315 (UVB) and/or 315-380 nm (UVA) range. This "uptake" of energy results in an electronic excitation, the compounds undergo a transition from the $S_0$ (ground) state to an excited $S_1$ state.

The excited singlet state ($S_1)$ may 


deactivate radiationless via internal conversion (IC), the energy of the photon is released as heat or 
undergo intersystem crossing (ISC) to a triplet state (usually $T_1)$ with different spin multiplicity


The latter state then might again loose its energy via IC or undergo a chemical transformation, through which the suncreen might be turned to a species that not longer is able to absorb UV radiation.