Hi! Pig farms are kind of awkward, but with a little redstone it's no problem at all. My friend xNiteowlx did this for me and I haven't had an issue since. The pistons have a delay so that the pigs have time to spawn. This can also be used for cows!
View attachment 30145
View attachment 30146
View attachment 30147
The hoppers NEED to be in a circle like this. Hope this helps! If you have any questions, DM me on discord (tiny#4510), reply to this, or visit me on Atlas to see it in person!