I have an application that rotates between landscape and portrait mode, which works great. However, it gets really jumpy and wants to rotate at 45deg at the slightest movement of the device. Is there a way to control the sensitivity of rotation, or prevent it from rotating until it hits certain targets (90, 180, 0) while ignoring the in-betweens?
+1
A:
You can probably keep a counter in the shouldAutorotateToInterfaceOrientation: method so that it needs to trigger a few times before you actually switch. Something like a "debounce" circuit in electronics.
(Aside: In electronics, if you're triggering some action whenever a physical button is pressed, you usually have to debounce it. This is because, since the button is a physical object, it won't make perfect contact when a user hits it. Usually there will be multiple short pulses while it makes contact. So the microprocessor keeps a count, and when the switch has been pressed for a full 10mS or something, then it actually triggers.)
So:
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation{
counter++: //ivar
if (counter > 2) {
counter=0;
return YES;
} else {
return NO;
}
}
Nathaniel Martin
2009-07-29 18:46:30
I would think this method only gets called once per orientation change. I doubt there's a way to fine-tune the orientation-change logic without processing raw accelerometer readings yourself.
Daniel Dickison
2009-07-29 18:55:29
Right, but if he's seeing it going back and forth, then it's getting called multiple times.Probably a better way would be to use this method to fire a delayed method that checks to see if it's still rotated, in which case it actually does the rotation.
Nathaniel Martin
2009-07-29 19:01:46
I wish I could just have it not rotate at 45deg. I don't want to process accelerometer readings though --> *scared*
Joel Hooks
2009-07-29 19:50:02