Does anyone know if it is possible to stop an autorotation once a shake gesture is recognized (i.e. don't autorotate during an aggress开发者_C百科ive shake)?
Autorotation is handled with some quirky low-level stuff which seems to change significantly betweeen major OS releases; I really wouldn't mess with it.
"Cancelling" doesn't really work either — in CoreAnimation speak, the animation has already happened in the "model tree" and the "presentation tree" and "render tree" are catching up. If you've saved the old orientation (i.e. on a rotation, save the old orientation and the time, and compare times) you can call [[UIDevice currentDevice] setOrientation:orientation] but Apple will reject your app.
If the rotation hasn't happened yet, then set a flag at the start of the shake and clear it at the end, and then override -shouldAutorotateForInterfaceOrientation: to return NO if a shake is currently happening.
Register your controller to check if a shake occurs by observing the device orientation, and set a flag in your controller for knowing that shake is currently happening (you could use the date). Then, override shouldAutorotateForInterfaceOrientation method to check the flag and avoid rotation in case the shake is happening now.
精彩评论