There are three reasons why it happens to me.
1. Like Joyscarer, giving leg aids with my heel makes my feet go into the stirrups. My horse tends to be dead to my leg, so as a result, I try to press harder.
Solution, squeeze with calves, then follow up with the whip if I don't get the reaction I require. This is working great so far.
2. Gripping. I am only just now being able to let go and stop gripping in canter, and I've been riding for a few years ! I see many other people with the same issue.
Solution: Try and sit up really straight, relax my legs and think about heavy legs.
3. Standing in the stirrups when trotting.
Solution: Rise from the knees, not by pushing down on the stirrups.
Fortunately I've managed to work out what I was doing to cause the problem, and Its going a long way towards fixing it. (Had a compliment from my old instructor when he saw me riding last week !!!)
Next problem I need to conquer is getting the "toes in" !