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
- device , app start in portrait.
- tap button toggle rotation off.
- rotate device landscape.
- device landscape, app portrait expected.
- 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
Post a Comment