I modified a nail-in electrical box to use screws instead of nails. Is there some code that prevents that?
Here's another type of adjustable box that you can use.  Just mount the box approximately where you want it and after you find the correct depth you can move it, even after drywall has been installed.



Here's the cut sheet on it.  Here.