Helloo !!
HERE IS THE SOLUTION:
I take just about the problem to get everyone to agree: I had the same concern you, specifically in terms of horizontal and vertical screen rotation with my Galaxy ACE but it should also run on S normally.
1 - Just at first when you are in Front page, lower the top window, or press notification and once the open window, set the "Auto Rotate" button. (normally it is green if you have enabled)
2 - Press the menu button, then Settings and then display. Once in normally display the box "rotate auto.screen" is already checked !! from the scroll you to: "Horizontal Calibration" once inside put the phone on a flat surface such as a table, and then rely on calibrated.
3 - Open an image or type a text message and switch the phone vertically and horizontally and normally everything works again!
4 - Repeated handling if it does not work, but this time by resetting the phone. But be careful you will lose everything (except what is stored in the SD card)
5 - It is now known months if it works ???