I apologize if this isn't quite up to the posting standards of r/AskHistorians, but I'll take a swing at it.
During the Yuan Dynasty, the Mongols had a fairly lenient policy towards foreigners including Christians. The succeeding Ming Dynasty (1368-1644) was significantly less tolerant. The noble eunuch Zheng He took hundreds of Chinese ships on a huge trading expedition all the way to East Africa, but never seemed to show much interest in establishing diplomatic relations with Europe in any meaningful capacity. In fact, Zheng He's mission wasn't exploratory in nature at all, mostly relying on trade routes that had been used by Chinese allies for hundreds of years. In addition, the Ming Dynasty had put in place extremely strict laws for how to deal with foreigners:
Foreigners were only allowed into China to pay tribute to the Emperor. No one was to speak to the Emperor directly.
The Emperor, in turn, would provide a gift as a symbol of benevolence.
Anyone caught smuggling goods to foreigners or otherwise attempting to interact with them in any meaningful capacity would be punished.
Trading was possible, but only under very strict circumstances-- foreign traders were not allowed to leave their boats, for example, which severely limited the trader's ability to take the initiative.
All of this isn't to say the Chinese were unaware of the Europeans-- they honestly just didn't have much interest in them. The Chinese were extremely suspicious of Europeans, and when the Portguese conquered the tributary state of Malaca in 1511 did not help.
In 1515, the Portuguese were finally allowed to enter the Imperial Court, but they were not received with a warm welcome. The Chinese were angry, and accused the Portuguese of having broken many of the laws that were designed to prevent them from getting this far, as well as accused them of lying and bribery. And, to be fair, these accusations weren't unfounded, but internal debates and politics within the Imperial Court about how to deal with foreign trade was almost certainly the real cause of frustration.
The Portuguese were sent back to Guangzhou, but they did manage to later establish trade with the Japanese.
In 1557, Wang Tso, the military commander of Macao, spoke of the Portuguese in such glowingly friendly terms as "unsavory", "subversive", and "shall be the cause for future anxieties." Many Chinese scholars at the time described the Portuguese in terms of metaphorical disease, with a scholar named Weng Lin-Hang calling the Portuguese "an ulcer in the south of China which threatens to burst."
In other words, the Chinese were not fond of Europeans at all. Far from the mysticism that the West often associates with the East, the Chinese largely viewed foreigners as rowdy, subversive, rebellious, and untrustworthy. The Chinese couldn't kick them out, though, because the Portuguese were paying a very handsome amount of money to stay there, and the Chinese needed that money to fund their military.
These attitudes began shifting in 1564 when the Portuguese came to Chinese aide during a mutiny off the coast of Macau. This, in addition to the Portuguese's endless patience with the harsh restrictions imposed on them, finally gave the Imperial Court the rationale they needed to open trade with the Portuguese. It was decided that the Chinese would attempt to tame the savages.
Pang Shang-peng wrote to the court in 1564 "The foreigners could be induced to undergo a tacit moral transformation to quell their evil desires and be subdued. Only then can the roots of disaster be eradicated."
Discussions throughout the early 1600s on how best to do this ranged from the heavy-handed "set fire to their ships at the first sign of defiance" to the less-than-ideal "set up trading ports where an official can keep tabs on the foreigners."
This Chinese attitude of cultural superiority is fairly well-noted in historical literature. "Whatever the name given by others, to the Chinese their country was 'the Celestial Empire'... or Chung Kuo -- the center as it were of the civilized universe."
- J.M. Braga; "China Landfall, 1513: Jorge Alvares' Voyage to China" published 1955
After that, the Chinese had to spend more money to defend the Koreans from the Japanese, and the Portuguese presence would be firmly established in China for the next few hundred years until the rest of the Western powers caught up.
Hope this answers your questions and also doesn't get removed. I used a combination of different sources, but the main one I relied on was linked there towards the end. I am happy to verify anything I may have misremembered.