It's not likely that the foreclosure is an event constituting default under your lease agreement. Read your lease to find the answer. It's most common that there is a provision regarding assignability of the lease.
Another way to look at the issue is to ask, "Why do you want out?"
The bank is interested in keeping the tenants in place so that the revenue continues to come in and the complex will be more appealing to a buyer. Banks don't like to run businesses. They simply want to get it sold to pay off the note.
As long as you are still getting the benefit of the lease without significant interference or other breach, your situation hasn't changed at all. You keep paying rent and enjoy your apartment.
However, you still need to review your lease agreement to see if the terms provide for a termination of your lease in case of a bankruptcy or foreclosure.