tzl
tzl

Reputation: 1590

shouldAutorotateToInterfaceOrientation: never called

I set supported Interface Orientations to be all except Portrait upside down under Deployment Info.

I would like to override shouldAutorotateToInterfaceOrientation: for custom behaviour. (i.e support landscape as per condition)

I only have one viewcontroller due to constraints(customized view transitions)

this is what the code in my appdelegate looks like:

self.viewController = [[MyController alloc]initWithNibName:nil bundle:nil];

self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
return YES;

and in myController.m, i override shouldAutorotateToInterfaceOrientation:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
    return YES;
}

the application autorotates to all orientations but portrait upside down and the call back is never called. I have tried the suggestion at change return from shouldAutorotateToInterfaceOrientation: at runTime with no success. why?

on a side note, what would be the best way to change rotation support at runtime?

update:

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration

gets called. I tried placing in

[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait];

with no success :(

Upvotes: 2

Views: 3378

Answers (2)

Nazir
Nazir

Reputation: 1975

Its Working for me:

- (BOOL)shouldAutorotate {
    return YES;
}

- (NSUInteger)supportedInterfaceOrientations {
    NSUInteger orientations = UIInterfaceOrientationMaskPortrait;
    if ([self isKindOfClass:[YourViewController class]]) { // Your view class
        orientations |= UIInterfaceOrientationMaskPortraitUpsideDown;
    }
    return orientations;
}

orientations:

orientations |= UIInterfaceOrientationMaskLandscapeLeft;
orientations |= UIInterfaceOrientationMaskLandscapeRight;

Upvotes: 1

tzl
tzl

Reputation: 1590

was using ios6

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation

is deprecated on ios6

Upvotes: 4

Related Questions