ios - after toggling shouldAutorotate, orientation off -


i have worked on while , googled related can think of.

i have button in app toggles rotation. when turn rotation off, rotate device, turn rotation on, need way match app orientation device orientation.

@interface viewcontroller () {     bool _rotationstatus; } 

method tied button press:

   -(void)togglerotation     {         if(_rotationstatus == no)         {                     _rotationstatus = yes;         }         else         {             _rotationstatus = no;         }     }   - (bool)shouldautorotate //only targeting ios 6 {     return !_rotationstatus; } 

this works great toggle rotation, when rotation turned on, orientation not "refresh" match device orientation until rotate device again.

for example

  1. device , app start in portrait.
  2. tap button toggle rotation off.
  3. rotate device landscape.
  4. device landscape, app portrait expected.
  5. tap button toggle rotation on

desired: app rotates landscape match device.

actual: app remains in portrait until rotation notification received.

i think way correct check device orientation, , check app orientation , match them when rotation toggled on.

i added method:

if ((uideviceorientationislandscape([uidevice currentdevice].orientation)) && ([[uiapplication sharedapplication] statusbarorientation] == uiinterfaceorientationportrait))         {             nslog(@"mis-matched device , app orientations");             //do rotation?             [[uiapplication sharedapplication] setstatusbarorientation: uiinterfaceorientationlandscaperight animated:yes];         } 

so full method looks this.

-(void)togglerotation {         if(_rotationstatus == no)         {                     _rotationstatus = yes;         }         else         {             _rotationstatus = no;              if ((uideviceorientationislandscape([uidevice currentdevice].orientation)) && ([[uiapplication sharedapplication] statusbarorientation] == uiinterfaceorientationportrait))           {               nslog(@"mis-matched device , app orientations");               //do rotation?               [[uiapplication sharedapplication] setstatusbarorientation: uiinterfaceorientationlandscaperight animated:yes];           }         } } 

the nslog prints when expect to, call setstatusbarorientation not result in rotation.

i'm ios rookie, sure doing many things wrong. there better way this?


Comments

Popular posts from this blog

python - How to create a legend for 3D bar in matplotlib? -

java - Multi-Label Document Classification -

php - Dynamic url re-writing using htaccess -