We find the solution to the Dirac equation for a massive neutrino with a magnetic moment propagating in background matter and interacting with the twisting magnetic field. In frames of the relativistic quantum mechanics approach to the description of neutrino evolution we use the obtained solution to derive neutrino wave functions satisfying the given initial condition. We apply the results to the analysis of neutrino spin oscillations in matter under the influence of the twisting magnetic field. Then on the basis of the yielded results we describe spin-flavor oscillations of Dirac neutrinos that mix and have non-vanishing matrix of magnetic moments. We again formulate the initial condition problem, derive neutrinos wave functions and calculate the transition probabilities for different magnetic moments matrices. The consistency of the obtained results with the quantum mechanical treatment of spin-flavor oscillations is discussed. We also consider several applications to astrophysical and cosmological neutrinos.