Students staying hours past end of office hours
You don't need a "trick" to solve this problem. They're staying past the end of your scheduled office hours because you have been tolerant of this so far. (I suspect they completely missed your subtle hints.)

It sounds like you have made it too easy for them to use you as a crutch, rather than doing the work on their own and then coming to you with specific, focused questions. (Very much like this situation.) It's not good for you and it's not good for them.

At the end of your scheduled office hours, say (with a smile):


  Thanks, everyone, for coming! Don't forget that if you need extra help, you can also schedule an appointment with me.


You can do the same thing at the end of a scheduled appointment:


  It seems like we made some progress here. If you realize you still have questions after working on this some more, you can schedule another appointment.


Then if you need more of a reason to usher them out the door, grab your jacket and announce that you're going out for some coffee/air/exercise/something to eat.

If you think students are using office hours productively and genuinely need more time with a TA, consider letting the course instructor know - perhaps he/she should hire another TA to offer extra support.