Question

my app is doing calculations and showing the results in a graph. When the device is rotating a new UIViewController is generated showing the graph in a landscape-oriented view. Therefore necessary parameters are passed to the new ViewController to create the graph. The app is crashing when the device is turned to landscape when the calculation is still running.

Is there a proper way to disable the used DeviceOrientationNotification temporarily?

-(void)calculate
{

disable DeviceOrientationNotification

...calculation code here

enable DeviceOrientationNotification again

} 

Thanks (don't beat me up again, even if the question appears to be stupid)

Was it helpful?

Solution

In iOS 5 and 6 there is a call back on UIViewcontrollers for autorotation. I would just set a flag when you start your calculation that you shouldn't autorotate and set it back when you are done.

//somewhere in .h or class extension or simple member variable
@property (nonatomic) BOOL shouldRotate;

// iOS 6
- (BOOL)shouldAutorotate {
    return self.shouldRotate;
}

- (NSUInteger)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskPortrait;//Return what is supported
}

// pre-iOS 6 support
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {

    return self.shouldRotate && //other interface check;
}

-(void)calculate{
     self.shouldRotate = NO;
     //do calculation
     self.shouldRotate = YES;
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top