Kingdom of Morocco is a West African successor state to the Wattasid dynasty. In 1472 the Marinid dynasty which lost Granada to Spain was overthrown and the Berber Wattasids got on the throne. The Wattasids promised protection against incursions, but the Kingdom of Portugal carved a pretty big piece of land.
In 1530 Joanna I decided to get rid of a possibility of a new muslim invasion, even though the last possible enemy for Spain was the Almohad dynasty which broke up in the 13th century. The Wattasids were already torn and they lost almost instantly. Joanna was crowned in a new capital of Ceuta. After this she never visited Morocco. Morocco became a property of a new dynasty The de Ceutas (Jaime de Ceutas, 1st Duke of Gibraltar). Charles I also never visited Morocco, as he was mainly troubled by the Muslims in the Balkans. His reign was so short that he was barely acknowledged in Morocco.