0

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.

user1488065
  • 3
  • 1
  • 3

3 Answers3

1

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);
spring
  • 18,009
  • 15
  • 80
  • 160
  • It makes rotation. But this way has a problem. When UIViewController's didRotateFromInterfaceOrientation called, view frame size is still unchanged value. If device rotated, the value is new value. – user1488065 Jun 28 '12 at 11:03
  • Are you changing what is returned by `shouldAutorotateToInterfaceOrientation` based on the user pref and the current orientation? Might take some more fiddling to get it to work - don't give up (yet! ;-) – spring Jun 28 '12 at 11:17
0

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;
}
Community
  • 1
  • 1
ejazz
  • 2,458
  • 1
  • 19
  • 29
-1

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

Bernd Rabe
  • 790
  • 6
  • 23