Obama wasn't necessarily anti-gay marriage, but like most liberals at the time (and like liberals for most issues), was sitting somewhere in the middle. He was in support of civil unions which would grant legal rights to gay partnerships but would leave the labeling of it as a marriage up to the states. A sort of "separate but equal" application to marriages. Did he actually believe this in his heart? Who knows, but that's what he said and did as a politician. It almost doesn't even matter what candidates say, they are looking to sway voters and donors, not actually make policies. You really just have to wait until a president's second term for progress to happen.
The slow march of progress has to navigate what is politically acceptable for most people of the time these changes take place in. Obama put in two of the justices that granted gay marriage rights during his first term.