0
votes

Hi,

I'm trying to implement orientation rotation lock / unlock toggle switch to my iOS app.

Locking is OK, but unlocking is a problem.

Suppose a situation that app's orientation and device's orientation are differ. If user unlocks in the situation, app's orientation should follow device's orientation immediately. But I cannot find the way.

How can I simulate device's orientation rotation?

Edit

I'll clarify the situation.

There is a toggle switch in app, enable/disable orientation rotation.

Step by step:

1. The switch is enabled.

2. Device rotates to portlait.

3. UIViewController's shouldAutorotateToInterfaceOrientation returns YES for every orientation.

4. App rotates to portlait.

5. User toggles the switch to disable.

6. Device rotates to landscape.

7. UIViewController's shouldAutorotateToInterfaceOrientation returns NO except portlait.

8. App doesn't rotate.

9. User toggles the switch to enable.

10. App should rotate to landscape. This is the problem.

3
Wait, how are you locking the orientation of the device?CodaFi
By implementing shouldAutorotateToInterfaceOrientation.user1488065

3 Answers

1
votes

I haven't tried it but there is a viewController method attemptRotationToDeviceOrientation (iOS5). Might be worth a shot. Interesting problem. Report back on if it works.

// call this method when your return value from shouldAutorotateToInterfaceOrientation: changes
// if the current interface orientation does not match the current device orientation, 
// a rotation may occur provided all relevant view controllers now return YES from shouldAutorotateToInterfaceOrientation:
+ (void)attemptRotationToDeviceOrientation __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_5_0);
0
votes

See my answer here: https://stackoverflow.com/a/13033443/580173

I made a custom UINavigationController, and there you can check in which view you are, and respond with the right masks. (I wanted the root view to be portrait)

- (BOOL)shouldAutorotate {
    return YES;
}

- (NSUInteger)supportedInterfaceOrientations
{
    if([self.viewControllers count] == 1) return UIInterfaceOrientationMaskPortrait;
    return UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscape;
}
-1
votes

You could read "Technical Q&A QA1688" which deals with autoratotion and in every viewcontroller make the message shouldAutorotateToInterfaceOrientation: return the correct value depending on your switch setting. There is also a switch in your info.plist. Marke sure you have the correct settings here as well