This post was published back in 2009. It may not function as originally intended or may be missing images.
One Touch Rotation Lock on the iPhone
One feature I get a lot of comments about in Read It Later Pro is the one touch rotation lock. When the user rotates their phone, it displays a lock icon for a brief second. If the user taps the lock, they can lock the rotation of the device so the view does not change. This is so much easier/faster than making a user go back out to the options screen and setting a toggle.
Since a lot of users have said they wished other applications had this feature I thought I'd release the source code so that other developers could easily add it if they wish.
How to Use
Every app is going to be unique, so depending on how your application and it's views are designed, this may or not be a quick drop-in.I would start first by downloading and viewing the example project.
There are two parts you would need to integrate into your application.
1. Add the view controller additions to your UIViewController
Open OneTouchRotationViewController.h and OneTouchRotationViewController.m. You will see the additional properties and functions I've added to the UIViewController. In most cases, you can simply copy and paste them into your main view controller.The example project has no extraneous methods or code, so you should carry over almost all of the code from the two files into your own.
Make sure you get:
- The definitions in the header (.h) file.
- The #defined degreesToRadians function at the top of the .m file
- The OneTouchRotation enum
- The synthesized properties line
- The hideLockAfterNumberOfSeconds constant
- All of the source for the rotation functions listed in the .m file