I haven't had pigs for long, but it seems like every time I've seen truffles, I was in the farm at the time they were dug up. Similarly, I haven't seen any truffles after being gone from the farm for almost the entirety of the day, but I'm not sure if it's a coincidence. So are pigs able to find and dig up truffles while you're not in the farm to see it happen?
Yesterday I collected my first truffle. I had been running around town all day, and discovered it sitting in my barnyard at the end of the day. It hadn't been there earlier in the day when I was on the farm. So, I conclude that truffles can be left by pigs regardless of whether you're on the farm or elsewhere.