It's quite tricky, but once you get enough practice in, it becomes easier.
The best way to think of it is to try and imagine where the hit box of your Pokémon is. Do you hit with the belly, shell, or top of the head for instance?
Now that you got that down, you need to remember that your Pokémon makes an animation when it tries to hit a yarn ball, which means if you hit it right when it enters your hitbox then your Pokémon won't have time to complete its animation.
Now it's up to timing, you wand the animation to reach the up bob motion right when the yearn ball falls into the hit box. Time it too early or too late you will lose. Try throwing a few matches to get the hang of it. Best of luck!