The exact mechanism to achieve variable valve timing depends on the way the manufacturer implements the concept.
BMW uses VANOS that changes the the timing of the inlet valve by rotating the camshaft in relation to the cam gear (double VANOS does the same with the exhaust valve).
Honda employs VTEC that varies the timing, valve lift and duration by using two sets of lobes on the camshaft.
In the case of the VTEC system the shift is effected by means of oil pressure after a solenoid is activated (under control from the ECU). When the solenoid is activated, oil under pressure activates a locking pin that binds the low rpm cam follower and the high rpm cam follower together and thus the valve opens and closes according to the high rpm cam profile.
With VANOS, oil under pressure is used (under control of the ECU) to effect the advancement/retardation of the camshaft timing at the cam gear.
In both systems, the camshaft itself does not move forward or rearward in relation to the engine.