Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot rotate interface orientation to portrait upside down

Both on iPhone simulator and iPhone 3GS (iOS 6) I cannot manage to set the orientation to portrait upside down. I have just one ViewController. I've added this code in it:

-(BOOL) shouldAutorotate{
 return YES; 
}

-(UIInterfaceOrientation) preferredInterfaceOrientationForPresentation{
 return UIInterfaceOrientationPortraitUpsideDown;
}

- (NSUInteger)supportedInterfaceOrientations{
 return UIInterfaceOrientationPortrait | UIInterfaceOrientationPortraitUpsideDown;
}

-(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation{
  if (toInterfaceOrientation==UIInterfaceOrientationPortrait || toInterfaceOrientation==UIInterfaceOrientationPortraitUpsideDown) {
    return YES;
  }
 return NO;
}

I also added this to AppDelegate.m:

-(NSUInteger) application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window{
    return UIInterfaceOrientationPortrait | UIInterfaceOrientationPortraitUpsideDown;
}

I've also checked the plist file, both orientations are present there. On my storyboard, at Simulated Metrics Orientation is set to Inferred. I do nothing in my applicationDidFinishLaunchingWithOptions, except return YES. I've just added a UIImageView inside of this ViewController. Is it possible to make this orientation work?

like image 212
Maxim Chetrusca Avatar asked Dec 27 '12 16:12

Maxim Chetrusca


1 Answers

supportedInterfaceOrientations returns an NSUInteger. It returns all of the interface orientations that the view controller supports, a mask of interface orientation values.

You need to return values defined in UIInterfaceOrientationMask Enum, like the following shows:

- (BOOL)shouldAutorotate {
    return YES;
}

- (NSUInteger)supportedInterfaceOrientations {
    return (UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown);
}
like image 131
Bejmax Avatar answered Sep 27 '22 23:09

Bejmax