Hi Hayls and welcome to the forums
It is good you care about your partner and try to help his anxieties. It is ok to have needs and desires. I had the same issue in the past. I decided to talk to them about it. It is ok to discuss how you sometimes want affection even if he is going through a rough patch. You can let him know thats how you are used to comforting him. Maybe he can explain how he feels and together you can compromise. Maybe hold hands instead of hug.
Have you or your partner ever talked to a counsellor or psychologist. I myself have anxiety. I find talking to someone helps me with my anxiety. Sometimes my anxiety overtakes me and I just want to lie in bed and make a blanket coacoon. It can be horrible feeling that way and you just want to be alone, because you worry you'll bring others down or you are scared people won't like what they see. It can be scary. Since I have talked about these things with a therapist I find it easier to open up to people and not feeling like a burden.
I hope this was helpful. I know it can be hard. But hang in there and be open with each other because it will help with better understanding