Samsung devices do this by checking the orientation of your face through the camera. They will also stay unlocked by checking if you're still looking (while reading a long page of text, for example) and also pause/play videos when you look away.
The problem, of course, is that none of this works when the lights are off - like when you're in bed - which is one of the most common use cases.
Images of options in phone settings: http://imgur.com/a/lyq6q