Wizard Of iOS
Wizard Of iOS

Reputation: 2399

UIDeviceOrientationDidChangeNotification called multiple times with a small change in accelerometer

I am using

[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(detectOrientation) name:@"UIDeviceOrientationDidChangeNotification" object:nil];

to make changes to some views in my appdelegate.

But this gets called in a slightest variation of the accelerometer. Can anyone suggest any workaround, so that it gets only called when the device is completely rotated. Thanks

Upvotes: 0

Views: 1971

Answers (2)

Zhang
Zhang

Reputation: 11607

Could you write some code to check the device's width = 480 and height = 320 (this is when the device has been rotated 90 degrees) before posting the notification?

So something like:

[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];

...

if(width == 480 && height == 320)
{
    [[NSNotificationCenter defaultCenter] postNotification . . . ];
}

Upvotes: 1

Arie Litovsky
Arie Litovsky

Reputation: 4993

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
     //your code here
}

override this method in your view controller. It will get called when the device has rotated to a new orientation

Upvotes: 0

Related Questions