I had this problem with a couple of pigs. They were living in a sty that was built into a range of Victorian farm buildings. The sty must have been designed for a sow and a litter of pigs as it is about 9 feet by 9 feet. The pigs tended to deposit their muck outside but urinated in the sty. The stench of ammonia was horrendous.
I picked up the tip, it may have been on this forum, that they had too much space. Since then I have partitioned of the sty with sheep hurdles and increased the living space as the pigs grow. Fouling of their sty has been eliminated, much to the relief of my olfactory organs.
Regards, Dave