Answer
The King of Portugal before John IV was Philip III of Spain as a result of the Iberian Union, a dynastic union of the crowns of Spain and Portugal between 1580 and 1640, formed when Philip II of Spain also became Philip I of Portugal, following the Portuguese succession crisis of 1580.