I have an application build for iOS7 with a UIViewController that should support landscape left-right and portrait - portrait upside down and other ViewControllers should support landscape left and right orientation alone. I have used the notification to notify the orientation change and refresh the subviews accordingly. I am also checking UIDevice's current orientation to rotate. The issue I am facing is that, even a slight shake or tilt triggers orientation change method which refreshes the views. I even get bizarre view frames then and there. I use beginGeneratingDeviceOrientationNotifications and endGeneratingDeviceOrientationNotifications on viewDidLoad and viewWillDisappear respectively. Is there any way I can restrict to device rotation alone?
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(deviceDidRotate:) name:UIDeviceOrientationDidChangeNotification object:nil]; // adding observer to notify when device rotates.
deviceDidRotate: gets called even for a small tilt or shake which I actually want to avoid.
UIDeviceOrientation orientation = [UIDevice currentDevice].orientation;
//Ignoring specific orientations
if (orientation == UIDeviceOrientationFaceUp||orientation == UIDeviceOrientationFaceDown ||orientation == UIDeviceOrientationUnknown)
{
return;
}
if ((UIDeviceOrientationIsPortrait(orientation) || UIDeviceOrientationIsLandscape(orientation))) {
[UIViewController attemptRotationToDeviceOrientation];
}
To avoid the tilt effect I am using this delegate method
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
[self handleViewArrangementWithCurrentOrientation];
}
How can I skip notification trigger on slight shake or tilt. I am actually having a animation on view refresh on orientation change which gives a flickering kind of effect and its frequent. I need to remove this. Please help guys.