IPhones can’t always figure out which way is up. There are plenty of times when you’re lying down or leaning back that the phone’s screen keeps shifting from portrait to landscape – now it’s portrait... and back to landscape. There is a way to stop this constant screen rotation.
If you can’t remember whether your screen has been locked or not, check for the lock icon next to your battery indicator in the top-right corner. Curiously, this trick only works vertically. You can't lock it to a horizontal orientation.
Locking the screen orientation prevents the display from switching between horizontal and vertical