Question

I want to lock Orientation for entire application if server sends 'Lock' message. When server send 'Unlock' orientation , i want the app to do auto rotate. I stored the value 'Lock' in NSUSerDefaults. In rootViewcontroller , it is working fine like if Lock is true, shouldAutoRotate method returns NO, and view does not rotate. But in other view controller, even lock is true, shouldAutoRotate is returning No, but View is still rotating.

I have created a category of UINavigationController for autorotation so that shouldAutorotate method is called from every class.

- (BOOL)shouldAutorotate
{
    NSString *AUTO_ROT =[[NSUserDefaults standardUserDefaults]valueForKey:@"AUTOROT"];

    if([AUTO_ROT caseInsensitiveCompare:@"true"] == NSOrderedSame)
    {
        return YES;
    }
    else{
        return NO;
    }
}

Please help me in this.

Was it helpful?

Solution

Are you sure the rotating view controller is also a child view controller of a UINavigationController (i.e. did you push it on the UINagivationController)?

If you presented it using presentViewController:animated:completion: for example the view controller itself would also need to implement shouldAutorotate.

On a side note, be cautious of overriding via category. A much better way would be to subclass UINavigationController and override the method in the subclass.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top