the way I've done this in the past is I set up "camera points" (dummy sprites) all throughout my layout... and they are all equal distance apart (I use the snap to grid - make grid size the viewport size). Then I have a piece of code that lerp-scrolls to the nearest camera point to the player (Pick nearest). You could build in a slight delay incase the player is right on the edge so it doesn't bounce back and forth too fast - or play with the lerp numbers.
EDIT:sorry.. I misread that you wanted the camera to scroll when you leave the screen.