Of course, it is hard to know for sure, but it sounds like there is a fear of intimacy that may be operating in these reactions. There are several reasons that can contribute to this, but the most common features have to do with fears that center on losing yourself to another. In other words, committing to an intimate relationship means that your identity would have to change, how you think of yourself in the world shifts, and it influences how other people react to you. Being connected to someone as an intimate partner is a responsibility. Who you are changes as a result of that commitment, and while it is often desired it is just as often feared. There is a loss that happens when we approach a deeper commitment.
It would probably be a good idea to have some individual therapy surrounding why the last relationship failed. After 4 years it may have gotten to the point where the relationship would have meant giving up a piece of yourself that you didn’t want to lose. This might explain why when in the relationship it didn’t feel bad, but why it got worse as time goes on. It might also explain why your feelings are intense and then detached. You get the best of feeling connected for a brief period of time without feeling threatened by the loss of part of you.
There is a book, a classic now, that is called the Dance Of Intimacy by Harriet Lerner that discusses the back and forth nature of wanting intimacy and then not for women.
The short version of understanding this pattern I that love is in the same envelop as a loss. To have intimacy with a genuine commitment is interpreted as losing yourself. Again, I am not sure if this is happening in your situation, but this is the most common reason for the back-and-forth feelings of desire and detachment. I’d recommend finding a good therapist in your area. The find help tab at the top of the page should help you connect to someone in your area.
Wishing you patience and peace,
Proof Positive Blog @ PsychCentral