Quantum control of the motional states of trapped ions through fast switching of trapping potentials