Spain's invasion could have caused a lot of trouble with the Ming, but you'd have to have a significant amount of luck (vastly more than the Manchus had OTL) before they could actually conquer anything beyond a few islands.
Some things that could have helped Spain's effort:
1. Civilian control of the Ming army - the Confucian ideal of bureaucrats being in charge of all aspects of the state (including the army) was a pretty deeply-ingrained one, and the Ming state took pains to place generals under bureaucratic/eunuch oversight. Unfortunately for the Ming, that could sometimes lead to amateurish and ineffectual leadership that would have definitely been outclassed by the Spanish conquistadors.
2. Corruption - Hongwu limited Ming officials' salary to basically a pittance, which was intended to reduce corruption but in fact encouraged it quite drastically, which had direct implications on the dynasty's military effectiveness. By the late Ming, bureaucrats regularly overstated supply requests by a factor of 2 in order to account for corruption, creating padded rosters and 'fake regiments' in the process. Corruption also reduced the appeal of the Ming Dynasty in the eyes of locals.
3. "Fence-sitting' behavior - while this phenomenon was a fair degrees weaker thanks to Neo-Confucianism and its emphasis on loyalty to the state, local Chinese elites have traditionally been more concerned about the preservation of their own power than the well-being of the state. So you could have situations where one short, sharp victory leads to mass defections from local leaders, bandit lords, pirate kings and so on.
Lastly, logistics works against Ming as well as Spain, though of course to a lesser degree compared with the latter. Assuming Spain starts their conquest on the southeast littoral, a Ming army will have to be collected from all parts of the country and will have to be provisioned with grain/gunpowder across hundreds of miles of bad land roads (assuming the Spanish maintain some form of naval dominance on the coast). The major North-South conduit of the Grand Canal is also quite vulnerable to naval power, and if the Spanish navy manages to cut that it would have a significant impact on the Ming Dynasty's operations in the southeast, as well as providing the Spanish court with more bullion from tax barges to justify further reinforcements.
As I said, it would take a great deal of luck for Spain to achieve a major triumph over the Ming, and total conquest is highly unlikely.
I think a possible scenario would be for Spain to attack just as Ming is being highly pressured on multiple fronts and also suffering from various droughts and famines. Spain's fleet establishes naval dominance over Chinese seas and cuts the Grand Canal at the Yangtze, while its conquistadors team up with local pirates and bandits to wreak havoc across the countryside, defeating poorly-armed local and regional forces as they come along.
The bullion they ship back to Spain convinces the Spanish/Portuguese that further 'investment' in China is warranted (this would also require a less volatile Europe), and larger forces are sent to China and expected to live off the land. At some point Ming authority in affected areas will become so weak that local magnates will start siding with Spain.