Had this issue after installing a new rear camera from ifixit. Camera would focus on object more than a foot away but anything closer than that was blurry. Tapping and dropping didn't help.
I opened the phone back up and noticed the ribbon cable that's connected to the flash didn't "bend" correctly and was covering up about 25% of the camera lens area. Once I bent the ribbon cable correctly, it was out of the camera's way and focus worked perfectly.