The iOS 4 firmware update includes a rotation lock feature, similar to the rotation lock switch found on the first generation iPad.
iPhone 4 ships with iOS 4 and also has this capability. To enable rotation lock and prevent the screen from automatically changing orientation when the iPhone is turned:
1. Double click the home button to bring up the multitasking bar.
UPDATE: iOS 4 features a built-in rotation lock function. Find out more information about how to use rotation lock here.
Some iPhone applications have preferences to set an accelerometer lock under Settings. When rotation is disabled, the orientation of the app stays fixed in one direction no matter which way the iPhone is turned.
Most commonly used apps such as Safari, Messaging, Mail and iPod do not have this feature available in the preferences. In contrast, orientation can be temporarily fixed when viewing photos on the iPhone Camera Roll or Photo Library.
Some iPhone applications have preferences to set an accelerometer lock, which keeps the orientation of the app in one direction no matter which way the iPhone turns. Unfortunately, most commonly used apps do not have this feature.
Rotation can be switched off when viewing photos on the iPhone Camera Roll or Photo Library. When viewing a photo, hold down with one finger on the photo as if you're trying to copy the image.